96 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx17 %std_cxx11-14 %s2// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx17 %std_cxx17- %s3 4// PR43645template<class T> struct a { // precxx17-note {{here}}6 T b() {7 return typename T::x();8 }9};10struct B {11 typedef B x;12};13B c() {14 a<B> x;15 return x.b();16}17 18// Some extra tests for invalid cases19template<class T> struct test2 { T b() { return typename T::a; } }; // expected-error{{expected '(' for function-style cast or type construction}}20template<class T> struct test3 { T b() { return typename a; } }; // expected-error{{expected a qualified name after 'typename'}} cxx17-error{{expected '(' for function-style cast or type construction}}21template<class T> struct test4 { T b() { return typename ::a; } }; // precxx17-error{{refers to non-type member}} expected-error{{expected '(' for function-style cast or type construction}}22 23// PR1288424namespace PR12884_original {25 template <typename T> struct A {26 struct B {27 template <typename U> struct X {};28 typedef int arg;29 };30 struct C {31 typedef B::X<typename B::arg> x; // precxx17-warning{{missing 'typename' prior to dependent type name 'B::X' is a C++20 extension}}32 };33 };34 35 template <> struct A<int>::B {36 template <int N> struct X {};37 static const int arg = 0;38 };39 40 A<int>::C::x a;41}42namespace PR12884_half_fixed {43 template <typename T> struct A {44 struct B {45 template <typename U> struct X {};46 typedef int arg;47 };48 struct C {49 typedef typename B::X<typename B::arg> x; // expected-error {{use 'template'}} expected-error {{refers to non-type}}50 };51 };52 53 template <> struct A<int>::B {54 template <int N> struct X {};55 static const int arg = 0; // expected-note {{here}}56 };57 58 A<int>::C::x a; // expected-note {{here}}59}60namespace PR12884_fixed {61 template <typename T> struct A {62 struct B {63 template <typename U> struct X {};64 typedef int arg;65 };66 struct C {67 typedef typename B::template X<B::arg> x;68 };69 };70 71 template <> struct A<int>::B {72 template <int N> struct X {};73 static const int arg = 0;74 };75 76 A<int>::C::x a; // ok77}78 79namespace preserve_keyword {80 template <class T> struct A {81 using type = T;82 };83 84 template <class T> using B = A<T>::type*; // precxx17-warning {{missing 'typename'}}85 void *t1 = *B<int>(); // expected-error {{lvalue of type 'A<int>::type' (aka 'int')}}86 87 template <class T> using C = typename A<T>::type*;88 void *t2 = *C<int>(); // expected-error {{lvalue of type 'typename A<int>::type' (aka 'int')}}89 90 using D = A<int>::type*;91 void *t3 = *D(); // expected-error {{lvalue of type 'A<int>::type' (aka 'int')}}92 93 using D = typename A<int>::type*;94 void *t4 = *D(); // expected-error {{lvalue of type 'typename A<int>::type' (aka 'int')}}95} // namespace preserve_keyword96