1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | template <typename T> struct type_name_is {}; template <typename T> void type_name_error(const T&) { // will error with type name: type_name_is<T>::showing_type_name(); } int main() { type_name_error(42u + -43); } |
dGVtcGxhdGUgPHR5cGVuYW1lIFQ+CnN0cnVjdCB0eXBlX25hbWVfaXMge307Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgVD4Kdm9pZCB0eXBlX25hbWVfZXJyb3IoY29uc3QgVCYpCnsKICAgIC8vIHdpbGwgZXJyb3Igd2l0aCB0eXBlIG5hbWU6CiAgICB0eXBlX25hbWVfaXM8VD46OnNob3dpbmdfdHlwZV9uYW1lKCk7Cn0KCmludCBtYWluKCkKewogICAgdHlwZV9uYW1lX2Vycm9yKDQydSArIC00Myk7Cn0K
prog.cpp: In function ‘void type_name_error(const T&) [with T = unsigned int]’: prog.cpp:13: instantiated from here prog.cpp:8: error: ‘showing_type_name’ is not a member of ‘type_name_is<unsigned int>’
-
result: Compilation error (maybe you wish to see an example for C++ 4.7.2)
Will display exact type in diagnostic.


