Does the use a simple-template-id in a nested-name-specifier unambiguously mean a class template specialization?

jack X
struct A{
    template<typename U>
    void T(){}
};
struct B{
    template<typename U>
    struct T{
       using type = U;
    };
};
struct C:A,B{

};
int main(){
    C::T<int>::type d;
}

This example is accepted by neither GCC nor Clang.

As per basic.lookup.qual#1

The name of a class or namespace member or enumerator can be referred to after the​::​ scope resolution operator ([expr.prim.id.qual]) applied to a nested-name-specifier that denotes its class, namespace, or enumeration. If a​::​ scope resolution operator in a nested-name-specifier is not preceded by a decltype-specifier, lookup of the name preceding that ​::​ considers only namespaces, types, and templates whose specializations are types.

That means that when looking up the declarations for the template name T, the specialization of T shall denote a type in this context. On the other hand, as per class.member.lookup#4

If C contains a declaration of the name f, the declaration set contains every declaration of f declared in C that satisfies the requirements of the language construct in which the lookup occurs.

Again, when looking up the template T in the scope of C, only those templates whose specialization is a type should be considered by this lookup. The scope of C does not have any declarations for T, hence the lookup will be performed for S(T,C) in every one of its base classes. The template T in A does not satisfy the requirement. Meanwhile, the template T declared in the scope of B does satisfy the requirement. So the lookup is not ambiguous and the B::T is the unique result. That means C::T<int>::type d should be well-formed. Why do both GCC and Clang reject this example? Can it be considered a bug of in both? If I missed something, what's the reason that this example should be ill-formed?

Davis Herring

The lookahead required to have the lookup for T depend on the :: even as the interpretation of < depends on the meaning of T is considered undesirable. As such, lookup for a name followed by < is not restricted to types and namespaces regardless of any >:: found later. P1787R6 fixed this, restricting the special lookup to identifiers immediately followed by :: (since other kinds of names can’t refer to types or namespaces anyway).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Does the use a simple-template-id in a nested-name-specifier unambiguously mean a class template specialization?

From Dev

Nested class template specialization

From Dev

Explicit specialization of nested class template in class template

From Dev

Syntax for specialization of nested template class

From Dev

Specialization of inherited nested template class

From Dev

Specialization of inherited nested template class

From Dev

class template specialization with template

From Dev

What does template's implicit specialization mean?

From Dev

How to use another class as a class template specialization

From Dev

Template function specialization for template class

From Dev

template class specialization at template constructor

From Dev

template class specialization at template constructor

From Dev

Template specialization for templated class

From Dev

Check if class is a template specialization?

From Dev

Class template member specialization

From Dev

Class template member specialization

From Dev

Check if class is a template specialization?

From Dev

Template specialization on template member of template class

From Dev

Template specialization on a non template method in a template class

From Dev

Template specialization on a non template method in a template class

From Dev

Template class specialization for template class and other types

From Dev

What does this syntax mean, `class template <class R, class ...Args> class name<R(Args...)>`

From Dev

What does this syntax mean, `class template <class R, class ...Args> class name<R(Args...)>`

From Dev

What does "The template arguments of a specialization are deduced from the arguments of the primary template" mean?

From Dev

Template Specialization Not Working with Derived Class

From Dev

Paradigm regarding template class specialization

From Dev

template class - member function specialization

From Dev

Template class partial specialization syntax

From Dev

Template specialization with a specific templated class

Related Related

  1. 1

    Does the use a simple-template-id in a nested-name-specifier unambiguously mean a class template specialization?

  2. 2

    Nested class template specialization

  3. 3

    Explicit specialization of nested class template in class template

  4. 4

    Syntax for specialization of nested template class

  5. 5

    Specialization of inherited nested template class

  6. 6

    Specialization of inherited nested template class

  7. 7

    class template specialization with template

  8. 8

    What does template's implicit specialization mean?

  9. 9

    How to use another class as a class template specialization

  10. 10

    Template function specialization for template class

  11. 11

    template class specialization at template constructor

  12. 12

    template class specialization at template constructor

  13. 13

    Template specialization for templated class

  14. 14

    Check if class is a template specialization?

  15. 15

    Class template member specialization

  16. 16

    Class template member specialization

  17. 17

    Check if class is a template specialization?

  18. 18

    Template specialization on template member of template class

  19. 19

    Template specialization on a non template method in a template class

  20. 20

    Template specialization on a non template method in a template class

  21. 21

    Template class specialization for template class and other types

  22. 22

    What does this syntax mean, `class template <class R, class ...Args> class name<R(Args...)>`

  23. 23

    What does this syntax mean, `class template <class R, class ...Args> class name<R(Args...)>`

  24. 24

    What does "The template arguments of a specialization are deduced from the arguments of the primary template" mean?

  25. 25

    Template Specialization Not Working with Derived Class

  26. 26

    Paradigm regarding template class specialization

  27. 27

    template class - member function specialization

  28. 28

    Template class partial specialization syntax

  29. 29

    Template specialization with a specific templated class

HotTag

Archive