Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 234233d

Browse files
author
Charles Li
committed
Lit C++11 Compatibility Patch #8
24 tests have been updated for C++11 compatibility. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@266387 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d077ad4 commit 234233d

File tree

24 files changed

+529
-92
lines changed

24 files changed

+529
-92
lines changed

test/CXX/basic/basic.lookup/basic.lookup.classref/p1.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-option -verify %s
2+
// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-option -verify -std=c++98 %s
3+
// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-option -verify -std=c++11 %s
24

35
// C++98 [basic.lookup.classref]p1:
46
// In a class member access expression (5.2.5), if the . or -> token is
@@ -21,10 +23,16 @@
2123

2224
// From PR 7247
2325
template<typename T>
24-
struct set{}; // expected-note{{lookup from the current scope refers here}}
26+
struct set{};
27+
#if __cplusplus <= 199711L
28+
// expected-note@-2 {{lookup from the current scope refers here}}
29+
#endif
2530
struct Value {
2631
template<typename T>
27-
void set(T value) {} // expected-note{{lookup in the object type 'Value' refers here}}
32+
void set(T value) {}
33+
#if __cplusplus <= 199711L
34+
// expected-note@-2 {{lookup in the object type 'Value' refers here}}
35+
#endif
2836

2937
void resolves_to_same() {
3038
Value v;
@@ -36,7 +44,10 @@ void resolves_to_different() {
3644
Value v;
3745
// The fact that the next line is a warning rather than an error is an
3846
// extension.
39-
v.set<double>(3.2); // expected-warning{{lookup of 'set' in member access expression is ambiguous; using member of 'Value'}}
47+
v.set<double>(3.2);
48+
#if __cplusplus <= 199711L
49+
// expected-warning@-2 {{lookup of 'set' in member access expression is ambiguous; using member of 'Value'}}
50+
#endif
4051
}
4152
{
4253
int set; // Non-template.

test/CXX/class/class.friend/p1.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
24

35
struct Outer {
46
struct Inner {
@@ -41,7 +43,10 @@ class A {
4143
UndeclaredSoFar x; // expected-error {{unknown type name 'UndeclaredSoFar'}}
4244

4345
void a_member();
44-
friend void A::a_member(); // expected-error {{friends cannot be members of the declaring class}}
46+
friend void A::a_member();
47+
#if __cplusplus <= 199711L
48+
// expected-error@-2 {{friends cannot be members of the declaring class}}
49+
#endif
4550
friend void a_member(); // okay (because we ignore class scopes when looking up friends)
4651
friend class A::AInner; // this is okay as an extension
4752
friend class AInner; // okay, refers to ::AInner

test/CXX/class/class.friend/p2.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
24

35
struct B0;
46

57
class A {
68
friend class B {}; // expected-error {{cannot define a type in a friend declaration}}
7-
friend int; // expected-warning {{non-class friend type 'int' is a C++11 extension}}
8-
friend B0; // expected-warning {{specify 'struct' to befriend 'B0'}}
9+
friend int;
10+
#if __cplusplus <= 199711L
11+
// expected-warning@-2 {{non-class friend type 'int' is a C++11 extension}}
12+
#endif
13+
friend B0;
14+
#if __cplusplus <= 199711L
15+
// expected-warning@-2 {{unelaborated friend declaration is a C++11 extension; specify 'struct' to befriend 'B0'}}
16+
#endif
917
friend class C; // okay
1018
};

test/CXX/stmt.stmt/stmt.dcl/p3.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
24

35
// PR10034
46
struct X {};
@@ -40,8 +42,16 @@ struct Z {
4042
};
4143

4244
void test_Z() {
43-
goto end; // expected-error{{cannot jump from this goto statement to its label}}
44-
Z z; // expected-note{{jump bypasses initialization of non-POD variable}}
45+
goto end;
46+
#if __cplusplus <= 199711L
47+
// expected-error@-2 {{cannot jump from this goto statement to its label}}
48+
#endif
49+
50+
Z z;
51+
#if __cplusplus <= 199711L
52+
// expected-note@-2 {{jump bypasses initialization of non-POD variable}}
53+
#endif
54+
4555
end:
4656
return;
4757
}

test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp

Lines changed: 110 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
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
3234
namespace 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+
}
Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4+
25
template<class T> struct A {
36
static T t; // expected-error{{static data member instantiated with function type 'int ()'}}
47
};
@@ -11,10 +14,17 @@ template<typename T> struct B {
1114
B<function> b; // expected-note{{instantiation of}}
1215

1316
template <typename T> int f0(void *, const T&); // expected-note{{candidate template ignored: substitution failure}}
14-
enum {e}; // expected-note{{unnamed type used in template argument was declared here}}
17+
enum {e};
18+
#if __cplusplus <= 199711L
19+
// expected-note@-2 {{unnamed type used in template argument was declared here}}
20+
#endif
1521

1622
void test_f0(int n) {
17-
int i = f0(0, e); // expected-warning{{template argument uses unnamed type}}
23+
int i = f0(0, e);
24+
#if __cplusplus <= 199711L
25+
// expected-warning@-2 {{template argument uses unnamed type}}
26+
#endif
27+
1828
int vla[n];
1929
f0(0, vla); // expected-error{{no matching function for call to 'f0'}}
2030
}
@@ -23,20 +33,50 @@ namespace N0 {
2333
template <typename R, typename A1> void f0(R (*)(A1));
2434
template <typename T> int f1(T);
2535
template <typename T, typename U> int f1(T, U);
26-
enum {e1}; // expected-note 2{{unnamed type used in template argument was declared here}}
27-
enum {e2}; // expected-note 2{{unnamed type used in template argument was declared here}}
28-
enum {e3}; // expected-note{{unnamed type used in template argument was declared here}}
36+
enum {e1};
37+
#if __cplusplus <= 199711L
38+
// expected-note@-2 2{{unnamed type used in template argument was declared here}}
39+
#endif
40+
41+
enum {e2};
42+
#if __cplusplus <= 199711L
43+
// expected-note@-2 2{{unnamed type used in template argument was declared here}}
44+
#endif
45+
46+
enum {e3};
47+
#if __cplusplus <= 199711L
48+
// expected-note@-2 {{unnamed type used in template argument was declared here}}
49+
#endif
2950

3051
template<typename T> struct X;
3152
template<typename T> struct X<T*> { };
3253

3354
void f() {
34-
f0( // expected-warning{{template argument uses unnamed type}}
35-
&f1<__typeof__(e1)>); // expected-warning{{template argument uses unnamed type}}
36-
int (*fp1)(int, __typeof__(e2)) = f1; // expected-warning{{template argument uses unnamed type}}
37-
f1(e2); // expected-warning{{template argument uses unnamed type}}
55+
f0(
56+
#if __cplusplus <= 199711L
57+
// expected-warning@-2 {{template argument uses unnamed type}}
58+
#endif
59+
60+
&f1<__typeof__(e1)>);
61+
#if __cplusplus <= 199711L
62+
// expected-warning@-2 {{template argument uses unnamed type}}
63+
#endif
64+
65+
int (*fp1)(int, __typeof__(e2)) = f1;
66+
#if __cplusplus <= 199711L
67+
// expected-warning@-2 {{template argument uses unnamed type}}
68+
#endif
69+
70+
f1(e2);
71+
#if __cplusplus <= 199711L
72+
// expected-warning@-2 {{template argument uses unnamed type}}
73+
#endif
74+
3875
f1(e2);
3976

40-
X<__typeof__(e3)*> x; // expected-warning{{template argument uses unnamed type}}
77+
X<__typeof__(e3)*> x;
78+
#if __cplusplus <= 199711L
79+
// expected-warning@-2 {{template argument uses unnamed type}}
80+
#endif
4181
}
4282
}

0 commit comments

Comments
 (0)