Clang has a non-standard attribute preferred_name
that is used e.g. in libc++ to spell std::basic_string<char>
as std::string
(which is more user-friendly).
I'm trying to use it for my own types, but it doesn't seem to work: https://gcc.godbolt.org/z/re4af1Pej
#include <iostream>#include <string>template <typename T>void foo(){ std::cout << __PRETTY_FUNCTION__ << '\n';}template<typename T> struct my_basic_string;using my_string = my_basic_string<char>;template<typename T> struct __attribute__((__preferred_name__(my_string))) my_basic_string;int main(){ foo<std::string>(); // std::string foo<my_string>(); // my_basic_string<char> -- But why not `my_string`?!}
Note that this must be tested on Clang, with -stdlib=libc++
(libstdc++ doesn't have this annotation, and prints std::basic_string<char>
instead of std::string
).
Am I getting the syntax wrong? I believe I'm doing the same thing as libc++ does: [1], [2].