Ambiguous injected class name is not an error

后端 未结 2 1303
甜味超标
甜味超标 2021-01-01 15:30

What I read in the C++ standard about injected class names contradicts (as I see it) with the behavior of a sample program I will present shortly. Here\'s what I read:

2条回答
  •  不知归路
    2021-01-01 16:01

    I found it! It's right there in the standard! I was right! It should be ambiguous!

    Clause 14.6.1 Paragraph

    A lookup that finds an injected-class-name (10.2) can result in an ambiguity in certain cases (for example, if it is found in more than one base class). If all of the injected-class-names that are found refer to specializations of the same class template, and if the name is followed by a template-argument-list, the reference refers to the class template itself and not a specialization thereof, and is not ambiguous. [Example:

    template  struct Base { };
    template  struct Derived: Base, Base 
    { 
        typename Derived::Base b; // error: ambiguous typename 
        Derived::Base d;  // OK 
    };
    

    —end example]

    Bottom line: This is yet another Microsoft compiler BUG. Disabling language extensions doesn't help either.

提交回复
热议问题