[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaTemplate / typename-specifier-3.cpp
blob714830f0032d2896e39cf4cd51f8556e5fe3928b
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
4 // PR4364
5 template<class T> struct a { // precxx17-note {{here}}
6 T b() {
7 return typename T::x();
9 };
10 struct B {
11 typedef B x;
13 B c() {
14 a<B> x;
15 return x.b();
18 // Some extra tests for invalid cases
19 template<class T> struct test2 { T b() { return typename T::a; } }; // expected-error{{expected '(' for function-style cast or type construction}}
20 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}}
21 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}}
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;
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}}
35 template <> struct A<int>::B {
36 template <int N> struct X {};
37 static const int arg = 0;
40 A<int>::C::x a;
42 namespace PR12884_half_fixed {
43 template <typename T> struct A {
44 struct B {
45 template <typename U> struct X {};
46 typedef int arg;
48 struct C {
49 typedef typename B::X<typename B::arg> x; // expected-error {{use 'template'}} expected-error {{refers to non-type}}
53 template <> struct A<int>::B {
54 template <int N> struct X {};
55 static const int arg = 0; // expected-note {{here}}
58 A<int>::C::x a; // expected-note {{here}}
60 namespace PR12884_fixed {
61 template <typename T> struct A {
62 struct B {
63 template <typename U> struct X {};
64 typedef int arg;
66 struct C {
67 typedef typename B::template X<B::arg> x;
71 template <> struct A<int>::B {
72 template <int N> struct X {};
73 static const int arg = 0;
76 A<int>::C::x a; // ok