1
1
// RUN: %clang_cc1 -fsyntax-only -verify -triple=x86_64-linux-gnu %s
2
+ // RUN: %clang_cc1 -fsyntax-only -verify -triple=x86_64-linux-gnu -std=c++98 %s
3
+ // RUN: %clang_cc1 -fsyntax-only -verify -triple=x86_64-linux-gnu -std=c++11 %s
2
4
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64-linux-gnu %s -DCPP11ONLY
3
5
4
6
// C++11 [temp.arg.nontype]p1:
@@ -31,55 +33,135 @@ namespace non_type_tmpl_param {
31
33
// if the corresopnding template-parameter is a reference; or
32
34
namespace addr_of_obj_or_func {
33
35
template <int * p> struct X0 { }; // expected-note 5{{here}}
36
+ #if __cplusplus >= 201103L
37
+ // expected-note@-2 2{{template parameter is declared here}}
38
+ #endif
39
+
34
40
template <int (*fp)(int )> struct X1 { };
35
41
template <int &p> struct X2 { }; // expected-note 4{{here}}
36
42
template <const int &p> struct X2k { }; // expected-note {{here}}
37
43
template <int (&fp)(int )> struct X3 { }; // expected-note 4{{here}}
38
44
39
45
int i = 42 ;
46
+ #if __cplusplus >= 201103L
47
+ // expected-note@-2 {{declared here}}
48
+ #endif
49
+
40
50
int iarr[10 ];
41
51
int f (int i);
42
- const int ki = 9 ; // expected-note 5{{here}}
43
- __thread int ti = 100 ; // expected-note 2{{here}}
44
- static int f_internal (int ); // expected-note 4{{here}}
52
+ const int ki = 9 ;
53
+ #if __cplusplus <= 199711L
54
+ // expected-note@-2 5{{non-type template argument refers to object here}}
55
+ #endif
56
+
57
+ __thread int ti = 100 ; // expected-note {{here}}
58
+ #if __cplusplus <= 199711L
59
+ // expected-note@-2 {{here}}
60
+ #endif
61
+
62
+ static int f_internal (int );
63
+ #if __cplusplus <= 199711L
64
+ // expected-note@-2 4{{non-type template argument refers to function here}}
65
+ #endif
66
+
45
67
template <typename T> T f_tmpl (T t);
46
68
struct S { union { int NonStaticMember; }; };
47
69
48
70
void test () {
49
- X0<i> x0a; // expected-error {{must have its address taken}}
71
+ X0<i> x0a;
72
+ #if __cplusplus <= 199711L
73
+ // expected-error@-2 {{non-type template argument for template parameter of pointer type 'int *' must have its address taken}}
74
+ #else
75
+ // expected-error@-4 {{non-type template argument of type 'int' is not a constant expression}}
76
+ // expected-note@-5 {{read of non-const variable 'i' is not allowed in a constant expression}}
77
+ #endif
50
78
X0<&i> x0a_addr;
51
79
X0<iarr> x0b;
52
80
X0<&iarr> x0b_addr; // expected-error {{cannot be converted to a value of type 'int *'}}
53
- X0<ki> x0c; // expected-error {{must have its address taken}} expected-warning {{internal linkage is a C++11 extension}}
54
- X0<&ki> x0c_addr; // expected-error {{cannot be converted to a value of type 'int *'}} expected-warning {{internal linkage is a C++11 extension}}
55
- X0<&ti> x0d_addr; // expected-error {{refers to thread-local object}}
81
+ X0<ki> x0c; // expected-error {{must have its address taken}}
82
+ #if __cplusplus <= 199711L
83
+ // expected-warning@-2 {{internal linkage is a C++11 extension}}
84
+ #endif
85
+
86
+ X0<&ki> x0c_addr; // expected-error {{cannot be converted to a value of type 'int *'}}
87
+ #if __cplusplus <= 199711L
88
+ // expected-warning@-2 {{internal linkage is a C++11 extension}}
89
+ #endif
90
+
91
+ X0<&ti> x0d_addr;
92
+ #if __cplusplus <= 199711L
93
+ // expected-error@-2 {{non-type template argument refers to thread-local object}}
94
+ #else
95
+ // expected-error@-4 {{non-type template argument of type 'int *' is not a constant expression}}
96
+ #endif
97
+
56
98
X1<f> x1a;
57
99
X1<&f> x1a_addr;
58
100
X1<f_tmpl> x1b;
59
101
X1<&f_tmpl> x1b_addr;
60
102
X1<f_tmpl<int > > x1c;
61
103
X1<&f_tmpl<int > > x1c_addr;
62
- X1<f_internal> x1d; // expected-warning {{internal linkage is a C++11 extension}}
63
- X1<&f_internal> x1d_addr; // expected-warning {{internal linkage is a C++11 extension}}
104
+ X1<f_internal> x1d;
105
+ #if __cplusplus <= 199711L
106
+ // expected-warning@-2 {{internal linkage is a C++11 extension}}
107
+ #endif
108
+
109
+ X1<&f_internal> x1d_addr;
110
+ #if __cplusplus <= 199711L
111
+ // expected-warning@-2 {{internal linkage is a C++11 extension}}
112
+ #endif
113
+
64
114
X2<i> x2a;
65
115
X2<&i> x2a_addr; // expected-error {{address taken}}
66
116
X2<iarr> x2b; // expected-error {{cannot bind to template argument of type 'int [10]'}}
67
117
X2<&iarr> x2b_addr; // expected-error {{address taken}}
68
- X2<ki> x2c; // expected-error {{ignores qualifiers}} expected-warning {{internal linkage is a C++11 extension}}
69
- X2k<ki> x2kc; // expected-warning {{internal linkage is a C++11 extension}}
70
- X2k<&ki> x2kc_addr; // expected-error {{address taken}} expected-warning {{internal linkage is a C++11 extension}}
118
+ X2<ki> x2c; // expected-error {{ignores qualifiers}}
119
+ #if __cplusplus <= 199711L
120
+ // expected-warning@-2 {{internal linkage is a C++11 extension}}
121
+ #endif
122
+
123
+ X2k<ki> x2kc;
124
+ #if __cplusplus <= 199711L
125
+ // expected-warning@-2 {{internal linkage is a C++11 extension}}
126
+ #endif
127
+
128
+ X2k<&ki> x2kc_addr; // expected-error {{address taken}}
129
+ #if __cplusplus <= 199711L
130
+ // expected-warning@-2 {{internal linkage is a C++11 extension}}
131
+ #endif
132
+
71
133
X2<ti> x2d_addr; // expected-error {{refers to thread-local object}}
72
134
X3<f> x3a;
73
135
X3<&f> x3a_addr; // expected-error {{address taken}}
74
136
X3<f_tmpl> x3b;
75
137
X3<&f_tmpl> x3b_addr; // expected-error {{address taken}}
76
138
X3<f_tmpl<int > > x3c;
77
139
X3<&f_tmpl<int > > x3c_addr; // expected-error {{address taken}}
78
- X3<f_internal> x3d; // expected-warning {{internal linkage is a C++11 extension}}
79
- X3<&f_internal> x3d_addr; // expected-error {{address taken}} expected-warning {{internal linkage is a C++11 extension}}
140
+ X3<f_internal> x3d;
141
+ #if __cplusplus <= 199711L
142
+ // expected-warning@-2 {{internal linkage is a C++11 extension}}
143
+ #endif
144
+
145
+ X3<&f_internal> x3d_addr; // expected-error {{address taken}}
146
+ #if __cplusplus <= 199711L
147
+ // expected-warning@-2 {{internal linkage is a C++11 extension}}
148
+ #endif
149
+
150
+ int n;
151
+ #if __cplusplus <= 199711L
152
+ // expected-note@-2 {{non-type template argument refers to object here}}
153
+ #else
154
+ // expected-note@-4 {{declared here}}
155
+ #endif
156
+
157
+ X0<&n> x0_no_linkage;
158
+ #if __cplusplus <= 199711L
159
+ // expected-error@-2 {{non-type template argument refers to object 'n' that does not have linkage}}
160
+ #else
161
+ // expected-error@-4 {{non-type template argument of type 'int *' is not a constant expression}}
162
+ // expected-note@-5 {{pointer to 'n' is not a constant expression}}
163
+ #endif
80
164
81
- int n; // expected-note {{here}}
82
- X0<&n> x0_no_linkage; // expected-error {{non-type template argument refers to object 'n' that does not have linkage}}
83
165
struct Local { static int f () {} }; // expected-note {{here}}
84
166
X1<&Local::f> x1_no_linkage; // expected-error {{non-type template argument refers to function 'f' that does not have linkage}}
85
167
X0<&S::NonStaticMember> x0_non_static; // expected-error {{non-static data member}}
@@ -96,7 +178,17 @@ namespace bad_args {
96
178
int i = 42 ;
97
179
X0<&i + 2 > x0a; // expected-error{{non-type template argument does not refer to any declaration}}
98
180
int * iptr = &i;
99
- X0<iptr> x0b; // expected-error{{non-type template argument for template parameter of pointer type 'int *' must have its address taken}}
181
+ #if __cplusplus >= 201103L
182
+ // expected-note@-2 {{declared here}}
183
+ #endif
184
+
185
+ X0<iptr> x0b;
186
+ #if __cplusplus <= 199711L
187
+ // expected-error@-2 {{non-type template argument for template parameter of pointer type 'int *' must have its address taken}}
188
+ #else
189
+ // expected-error@-4 {{non-type template argument of type 'int *' is not a constant expression}}
190
+ // expected-note@-5 {{read of non-constexpr variable 'iptr' is not allowed in a constant expression}}
191
+ #endif
100
192
}
101
193
#endif // CPP11ONLY
102
194
@@ -108,4 +200,4 @@ int f();
108
200
}
109
201
#endif // CPP11ONLY
110
202
111
- }
203
+ }
0 commit comments