bloomberg / clang-p2996

Experimental clang support for WG21 P2996 (Reflection).
https://github.com/bloomberg/clang-p2996/tree/p2996/P2996.md
57 stars 11 forks source link

has_template_arguments return false when used on "nested" template #41

Closed Pespon closed 5 months ago

Pespon commented 5 months ago

Bug Report Maybe I missed something. has_template_arguments return false when used on template type obtained through template_arguments_of.

Example

template<class T>
struct foo
{};

foo<int> foo1;
foo<decltype(foo1)> foo2;

int
main(void)
{
    std::cout << "A: name_of(type_of(^foo1)): " << name_of(type_of(^foo1)) << std::endl;
    std::cout << "B: has_template_arguments(type_of(^foo1)): " << has_template_arguments(type_of(^foo1)) << std::endl;
    std::cout << "C: name_of(template_arguments_of(type_of(^foo2))[0]): "
        << name_of(template_arguments_of(type_of(^foo2))[0]) << std::endl;
    constexpr bool test_result = (template_arguments_of(type_of(^foo2))[0] == type_of(^foo1));
    std::cout << "D: (template_arguments_of(type_of(^foo2))[0] == type_of(^foo1)): " << test_result << std::endl;
    std::cout << "E: has_template_arguments(template_arguments_of(type_of(^foo2))[0]): "
        << has_template_arguments(template_arguments_of(type_of(^foo2))[0]) << std::endl;
    std::cout << "F: name_of(template_arguments_of(template_arguments_of(type_of(^foo2))[0])[0]): "
        << name_of(template_arguments_of(template_arguments_of(type_of(^foo2))[0])[0]) << std::endl;
    return 0;
}

Expected behavior

The code above result in:
A: name_of(type_of(^foo1)): foo<int>
B: has_template_arguments(type_of(^foo1)): 1
C: name_of(template_arguments_of(type_of(^foo2))[0]): foo<int>
D: (template_arguments_of(type_of(^foo2))[0] == type_of(^foo1)): 1
E: has_template_arguments(template_arguments_of(type_of(^foo2))[0]): 0
F: name_of(template_arguments_of(template_arguments_of(type_of(^foo2))[0])[0]): int

All item above behave as expected except E. It shall be 'true' (1). Wich is strange since D and F work as expected

Additional context tested on commit c2764acc619ae358a42aa8d8fddd4bef7788aad6