Search code examples
c++visual-c++c++23

How to output identification of template arg T at design-time compilation?


always had this question and never asked, and running into a internal compilation error with hundreds of types. I just want to output the name of T, while its actually designing the functions, design-time compilation.

seems utterly the easiest thing to implement in a compiler? pragma message, pragma type. these things call when its generating them, so i see the message print over and over.

with msvc, an xmacro to get the name didnt work. i didnt want to add that to this question but it should be known i tried that too..

template <typename T>
void abc(T v) {

     /// not allowed (and i see no other pragmas?)
     #pragma message(T) // i need to output something identifying int.  doesnt have to be int but anything special even a hash or a size at the compilation stage here

}

int main(int argc, char *argv[]) {
   abc(int(1));
   return 0;
}

pragma is definitely outputting multiple times, its not like its some run-once thing. i see lots and lots of logs so its evaling with potential type name resolution. nothing at all available?


Solution

  • #pragma message(__PRETTY_FUNCTION__)
    

    this prints what i need.. i tried __FUNCTION__ and that was just class::method, but this beauty gives:

    struct ident *__cdecl ident::for_type<struct array<enum VkFormat>::adata,false>(void)
    

    things like that.. and thats very valuable.. much more valuable than bifurcating through a million types.