#include <typeinfo>
inline auto f() {
struct A { using type = decltype([]{}); };
return A{};
}
inline auto f(int) {
struct A { using type = decltype([]{}); };
return A{};
}
using B = decltype(f())::type;
using C = decltype(f(0))::type;
static_assert(!__is_same(B, C));
#if __cpp_lib_constexpr_typeinfo
static_assert(typeid(B) != typeid(C), "not eq at compile time");
#endif
int main() {
__builtin_printf("%s\n%s\n", typeid(B).name(), typeid(C).name());
__builtin_printf("eq at runtime? %d\n", typeid(B) == typeid(C));
}
The output produced is:
N1f1AUlvE_E
N1f1AUlvE_E
eq at runtime? 1
When they are clearly different types. For reference, the GCC output is:
Z1fvEN1AUlvE_E
Z1fiEN1AUlvE_E
eq at runtime? 0
Where N1f is replaced with Z1fvE or Z1fiE depending on the function signature (i.e., the function signature is just not taken into account in the mangling).
https://godbolt.org/z/E5EbbK3MW
```c++
#include <typeinfo>
inline auto f() {
struct A { using type = decltype([]{}); };
return A{};
}
inline auto f(int) {
struct A { using type = decltype([]{}); };
return A{};
}
using B = decltype(f())::type;
using C = decltype(f(0))::type;
static_assert(!__is_same(B, C));
#if __cpp_lib_constexpr_typeinfo
static_assert(typeid(B) != typeid(C), "not eq at compile time");
#endif
int main() {
__builtin_printf("%s\n%s\n", typeid(B).name(), typeid(C).name());
__builtin_printf("eq at runtime? %d\n", typeid(B) == typeid(C));
}
```
The output produced is:
```
N1f1AUlvE_E
N1f1AUlvE_E
eq at runtime? 1
```
When they are clearly different types. For reference, the GCC output is:
```
Z1fvEN1AUlvE_E
Z1fiEN1AUlvE_E
eq at runtime? 0
```
Where `N1f` is replaced with `Z1fvE` or `Z1fiE` depending on the function signature (i.e., the function signature is just not taken into account in the mangling).
https://godbolt.org/z/E5EbbK3MW
The output produced is:
When they are clearly different types. For reference, the GCC output is:
Where
N1f
is replaced withZ1fvE
orZ1fiE
depending on the function signature (i.e., the function signature is just not taken into account in the mangling).