annotate clang/test/SemaTemplate/nested-name-spec-template.cpp @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900 (2021-07-18)
parents 0572611fdcc8
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
anatofuz
parents:
diff changeset
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 namespace N {
anatofuz
parents:
diff changeset
6 namespace M {
anatofuz
parents:
diff changeset
7 template<typename T> struct Promote;
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 template<> struct Promote<short> {
anatofuz
parents:
diff changeset
10 typedef int type;
anatofuz
parents:
diff changeset
11 };
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 template<> struct Promote<int> {
anatofuz
parents:
diff changeset
14 typedef int type;
anatofuz
parents:
diff changeset
15 };
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 template<> struct Promote<float> {
anatofuz
parents:
diff changeset
18 typedef double type;
anatofuz
parents:
diff changeset
19 };
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 Promote<short>::type *ret_intptr(int* ip) { return ip; }
anatofuz
parents:
diff changeset
22 Promote<int>::type *ret_intptr2(int* ip) { return ip; }
anatofuz
parents:
diff changeset
23 }
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 M::Promote<int>::type *ret_intptr3(int* ip) { return ip; }
anatofuz
parents:
diff changeset
26 M::template Promote<int>::type *ret_intptr4(int* ip) { return ip; }
anatofuz
parents:
diff changeset
27 #if __cplusplus <= 199711L
anatofuz
parents:
diff changeset
28 // expected-warning@-2 {{'template' keyword outside of a template}}
anatofuz
parents:
diff changeset
29 #endif
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 M::template Promote<int> pi;
anatofuz
parents:
diff changeset
32 #if __cplusplus <= 199711L
anatofuz
parents:
diff changeset
33 // expected-warning@-2 {{'template' keyword outside of a template}}
anatofuz
parents:
diff changeset
34 #endif
anatofuz
parents:
diff changeset
35 }
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 N::M::Promote<int>::type *ret_intptr5(int* ip) { return ip; }
anatofuz
parents:
diff changeset
38 ::N::M::Promote<int>::type *ret_intptr6(int* ip) { return ip; }
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41 N::M::template; // expected-error{{expected unqualified-id}}
anatofuz
parents:
diff changeset
42 N::M::template Promote; // expected-error{{expected unqualified-id}}
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 namespace N {
anatofuz
parents:
diff changeset
45 template<typename T> struct A;
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 template<>
anatofuz
parents:
diff changeset
48 struct A<int> {
anatofuz
parents:
diff changeset
49 struct X;
anatofuz
parents:
diff changeset
50 };
anatofuz
parents:
diff changeset
51
anatofuz
parents:
diff changeset
52 struct B; // expected-note{{declared as a non-template here}}
anatofuz
parents:
diff changeset
53 }
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55 struct ::N::A<int>::X {
anatofuz
parents:
diff changeset
56 int foo;
anatofuz
parents:
diff changeset
57 };
anatofuz
parents:
diff changeset
58
anatofuz
parents:
diff changeset
59 template<typename T>
anatofuz
parents:
diff changeset
60 struct TestA {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
61 typedef typename N::template B<T>::type type; // expected-error{{'B' following the 'template' keyword does not refer to a template}}
150
anatofuz
parents:
diff changeset
62 };
anatofuz
parents:
diff changeset
63
anatofuz
parents:
diff changeset
64 // Reduced from a Boost failure.
anatofuz
parents:
diff changeset
65 namespace test1 {
anatofuz
parents:
diff changeset
66 template <class T> struct pair {
anatofuz
parents:
diff changeset
67 T x;
anatofuz
parents:
diff changeset
68 T y;
anatofuz
parents:
diff changeset
69
anatofuz
parents:
diff changeset
70 static T pair<T>::* const mem_array[2];
anatofuz
parents:
diff changeset
71 };
anatofuz
parents:
diff changeset
72
anatofuz
parents:
diff changeset
73 template <class T>
anatofuz
parents:
diff changeset
74 T pair<T>::* const pair<T>::mem_array[2] = { &pair<T>::x, &pair<T>::y };
anatofuz
parents:
diff changeset
75 }
anatofuz
parents:
diff changeset
76
anatofuz
parents:
diff changeset
77 typedef int T;
anatofuz
parents:
diff changeset
78 namespace N1 {
anatofuz
parents:
diff changeset
79 template<typename T> T f0();
anatofuz
parents:
diff changeset
80 }
anatofuz
parents:
diff changeset
81
anatofuz
parents:
diff changeset
82 template<typename T> T N1::f0() { }
anatofuz
parents:
diff changeset
83
anatofuz
parents:
diff changeset
84 namespace PR7385 {
anatofuz
parents:
diff changeset
85 template< typename > struct has_xxx0
anatofuz
parents:
diff changeset
86 {
anatofuz
parents:
diff changeset
87 template< typename > struct has_xxx0_introspect
anatofuz
parents:
diff changeset
88 {
anatofuz
parents:
diff changeset
89 template< typename > struct has_xxx0_substitute ;
anatofuz
parents:
diff changeset
90 template< typename V >
anatofuz
parents:
diff changeset
91 int int00( has_xxx0_substitute < typename V::template xxx< > > = 0 );
anatofuz
parents:
diff changeset
92 };
anatofuz
parents:
diff changeset
93 static const int value = has_xxx0_introspect<int>::value; // expected-error{{no member named 'value'}}
anatofuz
parents:
diff changeset
94 typedef int type;
anatofuz
parents:
diff changeset
95 };
anatofuz
parents:
diff changeset
96
anatofuz
parents:
diff changeset
97 has_xxx0<int>::type t; // expected-note{{instantiation of}}
anatofuz
parents:
diff changeset
98 }
anatofuz
parents:
diff changeset
99
anatofuz
parents:
diff changeset
100 namespace PR7725 {
anatofuz
parents:
diff changeset
101 template<class ignored> struct TypedefProvider;
anatofuz
parents:
diff changeset
102 template<typename T>
anatofuz
parents:
diff changeset
103 struct TemplateClass : public TypedefProvider<T>
anatofuz
parents:
diff changeset
104 {
anatofuz
parents:
diff changeset
105 void PrintSelf() {
anatofuz
parents:
diff changeset
106 TemplateClass::Test::PrintSelf();
anatofuz
parents:
diff changeset
107 }
anatofuz
parents:
diff changeset
108 };
anatofuz
parents:
diff changeset
109 }
anatofuz
parents:
diff changeset
110
anatofuz
parents:
diff changeset
111 namespace PR9226 {
anatofuz
parents:
diff changeset
112 template<typename a>
anatofuz
parents:
diff changeset
113 void nt() // expected-note{{function template 'nt' declared here}}
anatofuz
parents:
diff changeset
114 { nt<>:: } // expected-error{{qualified name refers into a specialization of function template 'nt'}} \
anatofuz
parents:
diff changeset
115 // expected-error{{expected unqualified-id}}
anatofuz
parents:
diff changeset
116
anatofuz
parents:
diff changeset
117 template<typename T>
anatofuz
parents:
diff changeset
118 void f(T*); // expected-note{{function template 'f' declared here}}
anatofuz
parents:
diff changeset
119
anatofuz
parents:
diff changeset
120 template<typename T>
anatofuz
parents:
diff changeset
121 void f(T*, T*); // expected-note{{function template 'f' declared here}}
anatofuz
parents:
diff changeset
122
anatofuz
parents:
diff changeset
123 void g() {
anatofuz
parents:
diff changeset
124 f<int>:: // expected-error{{qualified name refers into a specialization of function template 'f'}}
anatofuz
parents:
diff changeset
125 } // expected-error{{expected unqualified-id}}
anatofuz
parents:
diff changeset
126
anatofuz
parents:
diff changeset
127 struct X {
anatofuz
parents:
diff changeset
128 template<typename T> void f(); // expected-note{{function template 'f' declared here}}
anatofuz
parents:
diff changeset
129 };
anatofuz
parents:
diff changeset
130
anatofuz
parents:
diff changeset
131 template<typename T, typename U>
anatofuz
parents:
diff changeset
132 struct Y {
anatofuz
parents:
diff changeset
133 typedef typename T::template f<U> type; // expected-error{{template name refers to non-type template 'X::template f'}}
anatofuz
parents:
diff changeset
134 };
anatofuz
parents:
diff changeset
135
anatofuz
parents:
diff changeset
136 Y<X, int> yxi; // expected-note{{in instantiation of template class 'PR9226::Y<PR9226::X, int>' requested here}}
anatofuz
parents:
diff changeset
137 }
anatofuz
parents:
diff changeset
138
anatofuz
parents:
diff changeset
139 namespace PR9449 {
anatofuz
parents:
diff changeset
140 template <typename T>
anatofuz
parents:
diff changeset
141 struct s; // expected-note{{template is declared here}}
anatofuz
parents:
diff changeset
142
anatofuz
parents:
diff changeset
143 template <typename T>
anatofuz
parents:
diff changeset
144 void f() {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
145 int s<T>::template n<T>::* f; // expected-error{{implicit instantiation of undefined template 'PR9449::s<int>'}}
150
anatofuz
parents:
diff changeset
146 }
anatofuz
parents:
diff changeset
147
anatofuz
parents:
diff changeset
148 template void f<int>(); // expected-note{{in instantiation of}}
anatofuz
parents:
diff changeset
149 }