Is it possible to extend typedef with forced compiler error?

I used the method shown below to make the compiler yell at me for a variable type:

template <class T>
struct show_type;

Using it with the desired variable, therefore, compiler errors have an incomplete structure type:

typedef int32_t s32;
s32 a;
show_type<decltype(a)>();

Thus, GCC 5.3.0 generates an error:

Invalid use of incomplete type < struct show_type<int>'

And MSVC 2015:

' show_type<s32>': no ​​suitable default constructor

Now I wonder if there is a way to make the error show the full hierarchy typedef(i.e. s32 -> int32_t -> int), or at least the newest typedefand first original type? I am not against dirty or evil tricks.

+4
1

, typedefs (.. s32 -> int32_t -> int) , , typedef ?

. s32 - int32_t - int. , . - .


, , - , P0194. - :

using meta_s32   = reflexpr(s32);
using meta_int32 = meta::get_aliased_t<meta_s32>;
using meta_int   = meta::get_aliased_t<meta_int32>;
std::cout << meta::get_name_v<meta_s32> << ", "
          << meta::get_name_v<meta_int32> << ", "
          << meta::get_name_v<meta_int> << '\n';

, get_aliased_t , is_alias_v false_type.

+2

Source: https://habr.com/ru/post/1653033/


All Articles