3

Premise: g++ and clang++ are known to be sometime discordant or not compliant on applying the rules for template disambiguation for dependent names.

In this regard, the following code compiles under g++ but does not under clang++:

template<class T1>
struct A {
    template <class T2>
    class Anested {
        public:
        typedef A<T2> Other;
    };
};

template <class T>
struct B {
    typedef B<T> Myself;
    typedef typename T::Anested<Myself>::Other Other; //clang++ requires "template" before "Anested" to compile
};

int main() {
    B<A<void>> b;
}

clang++ is compliant in this case (isn't it?), but I am wondering whether the "template" keyword is actually redundant in this kind of statement. If it is not redundant, could you please make some examples to prove that the deduction rule followed by g++ is flawed?

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
JtTest
  • 47
  • 9
  • Probably because GCC-10 implements some features. [demo](https://godbolt.org/z/E7Y13dM4W) – 康桓瑋 Apr 30 '22 at 10:40
  • 1
    https://en.cppreference.com/w/cpp/compiler_support says that clang does not implement [P0634R3](https://wg21.link/P0634R3) yet, which might be what allows this? (unsure since this is the omission of `template`, not `typename`) But I think this is a GCC bug since it is allowed with `-std=c++17 -pedantic` – Artyer Apr 30 '22 at 11:04
  • @Artyer MSVC is said to have implemented that paper but it also refuses to compile without `template`. Besides the paper is about `typename` not `template`. – ixSci Apr 30 '22 at 14:26
  • @ixSci: `template` was given the same behavior as a DR. – Davis Herring Apr 30 '22 at 21:08

0 Answers0