11// 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
24// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -triple=x86_64-linux-gnu %s -DCPP11ONLY
35
46// C++11 [temp.arg.nontype]p1:
@@ -31,55 +33,135 @@ namespace non_type_tmpl_param {
3133// if the corresopnding template-parameter is a reference; or
3234namespace addr_of_obj_or_func {
3335 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+
3440 template <int (*fp)(int )> struct X1 { };
3541 template <int &p> struct X2 { }; // expected-note 4{{here}}
3642 template <const int &p> struct X2k { }; // expected-note {{here}}
3743 template <int (&fp)(int )> struct X3 { }; // expected-note 4{{here}}
3844
3945 int i = 42 ;
46+ #if __cplusplus >= 201103L
47+ // expected-note@-2 {{declared here}}
48+ #endif
49+
4050 int iarr[10 ];
4151 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+
4567 template <typename T> T f_tmpl (T t);
4668 struct S { union { int NonStaticMember; }; };
4769
4870 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
5078 X0<&i> x0a_addr;
5179 X0<iarr> x0b;
5280 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+
5698 X1<f> x1a;
5799 X1<&f> x1a_addr;
58100 X1<f_tmpl> x1b;
59101 X1<&f_tmpl> x1b_addr;
60102 X1<f_tmpl<int > > x1c;
61103 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+
64114 X2<i> x2a;
65115 X2<&i> x2a_addr; // expected-error {{address taken}}
66116 X2<iarr> x2b; // expected-error {{cannot bind to template argument of type 'int [10]'}}
67117 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+
71133 X2<ti> x2d_addr; // expected-error {{refers to thread-local object}}
72134 X3<f> x3a;
73135 X3<&f> x3a_addr; // expected-error {{address taken}}
74136 X3<f_tmpl> x3b;
75137 X3<&f_tmpl> x3b_addr; // expected-error {{address taken}}
76138 X3<f_tmpl<int > > x3c;
77139 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
80164
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}}
83165 struct Local { static int f () {} }; // expected-note {{here}}
84166 X1<&Local::f> x1_no_linkage; // expected-error {{non-type template argument refers to function 'f' that does not have linkage}}
85167 X0<&S::NonStaticMember> x0_non_static; // expected-error {{non-static data member}}
@@ -96,7 +178,17 @@ namespace bad_args {
96178 int i = 42 ;
97179 X0<&i + 2 > x0a; // expected-error{{non-type template argument does not refer to any declaration}}
98180 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
100192}
101193#endif // CPP11ONLY
102194
@@ -108,4 +200,4 @@ int f();
108200}
109201#endif // CPP11ONLY
110202
111- }
203+ }
0 commit comments