1 // RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx17 %std_cxx11-14 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx17 %std_cxx17- %s
3
4 // PR4364
5 template<class T> struct a { // precxx17-note {{here}}
ba6 T b() {
7 return typename T::x();
8 }
9 };
10 struct B {
11 typedef B x;
12 };
c()13 B c() {
14 a<B> x;
15 return x.b();
16 }
17
18 // Some extra tests for invalid cases
btest219 template<class T> struct test2 { T b() { return typename T::a; } }; // expected-error{{expected '(' for function-style cast or type construction}}
btest320 template<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}}
btest421 template<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 // PR12884
24 namespace 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; implicit 'typename' 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 }
42 namespace 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 }
60 namespace 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; // ok
77 }
78