blob: 26882321220ebef3eb419a00aac20ed29f69429c [file] [log] [blame]
Richard Smith41be6732011-10-14 20:48:27 +00001// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat -verify %s
Richard Smithebaf0e62011-10-18 20:49:44 +00002// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s
Richard Smith84ef8992011-10-14 20:41:13 +00003
Richard Smith03544fc2012-04-19 06:58:00 +00004namespace std {
5 struct type_info;
6 using size_t = decltype(sizeof(0)); // expected-warning {{decltype}} expected-warning {{alias}}
7 template<typename T> struct initializer_list {
8 initializer_list(T*, size_t);
9 T *p;
10 size_t n;
11 };
12}
Richard Smithd390de92012-02-25 10:20:59 +000013
Richard Smith84ef8992011-10-14 20:41:13 +000014template<typename ...T> // expected-warning {{variadic templates are incompatible with C++98}}
15class Variadic1 {};
16
17template<template<typename> class ...T> // expected-warning {{variadic templates are incompatible with C++98}}
18class Variadic2 {};
19
20template<int ...I> // expected-warning {{variadic templates are incompatible with C++98}}
21class Variadic3 {};
Richard Smith41be6732011-10-14 20:48:27 +000022
23int alignas(8) with_alignas; // expected-warning {{'alignas' is incompatible with C++98}}
24int with_attribute [[ ]]; // expected-warning {{attributes are incompatible with C++98}}
Richard Smith661a9962011-10-15 01:18:56 +000025
26void Literals() {
27 (void)u8"str"; // expected-warning {{unicode literals are incompatible with C++98}}
28 (void)u"str"; // expected-warning {{unicode literals are incompatible with C++98}}
29 (void)U"str"; // expected-warning {{unicode literals are incompatible with C++98}}
30 (void)u'x'; // expected-warning {{unicode literals are incompatible with C++98}}
31 (void)U'x'; // expected-warning {{unicode literals are incompatible with C++98}}
32
33 (void)u8R"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}}
34 (void)uR"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}}
35 (void)UR"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}}
36 (void)R"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}}
37 (void)LR"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}}
38}
39
40template<typename T> struct S {};
Richard Smith7fe62082011-10-15 05:09:34 +000041namespace TemplateParsing {
42 S<::S<void> > s; // expected-warning {{'<::' is treated as digraph '<:' (aka '[') followed by ':' in C++98}}
43 S< ::S<void>> t; // expected-warning {{consecutive right angle brackets are incompatible with C++98 (use '> >')}}
44}
45
46void Lambda() {
Richard Smithb9c64d82012-02-16 20:41:22 +000047 []{}(); // expected-warning {{lambda expressions are incompatible with C++98}}
Richard Smith7fe62082011-10-15 05:09:34 +000048}
49
Richard Smith03544fc2012-04-19 06:58:00 +000050struct Ctor {
51 Ctor(int, char);
52 Ctor(double, long);
53};
54struct InitListCtor {
55 InitListCtor(std::initializer_list<bool>);
56};
57
Sebastian Redl3e280b52012-03-18 22:25:45 +000058int InitList(int i = {}) { // expected-warning {{generalized initializer lists are incompatible with C++98}} \
59 // expected-warning {{scalar initialized from empty initializer list is incompatible with C++98}}
Sebastian Redl56a04282012-02-11 23:51:08 +000060 (void)new int {}; // expected-warning {{generalized initializer lists are incompatible with C++98}} \
61 // expected-warning {{scalar initialized from empty initializer list is incompatible with C++98}}
Sebastian Redl6dc00f62012-02-12 18:41:05 +000062 (void)int{}; // expected-warning {{generalized initializer lists are incompatible with C++98}} \
63 // expected-warning {{scalar initialized from empty initializer list is incompatible with C++98}}
Richard Smith6b130222011-10-18 21:39:00 +000064 int x { 0 }; // expected-warning {{generalized initializer lists are incompatible with C++98}}
Richard Smithdbe01bb2012-02-26 23:49:01 +000065 S<int> s = {}; // ok, aggregate
66 s = {}; // expected-warning {{generalized initializer lists are incompatible with C++98}}
Richard Smith03544fc2012-04-19 06:58:00 +000067 std::initializer_list<int> xs = { 1, 2, 3 }; // expected-warning {{initialization of initializer_list object is incompatible with C++98}}
68 auto ys = { 1, 2, 3 }; // expected-warning {{initialization of initializer_list object is incompatible with C++98}} \
69 // expected-warning {{'auto' type specifier is incompatible with C++98}}
70 Ctor c1 = { 1, 2 }; // expected-warning {{constructor call from initializer list is incompatible with C++98}}
71 Ctor c2 = { 3.0, 4l }; // expected-warning {{constructor call from initializer list is incompatible with C++98}}
72 InitListCtor ilc = { true, false }; // expected-warning {{initialization of initializer_list object is incompatible with C++98}}
73 const int &r = { 0 }; // expected-warning {{reference initialized from initializer list is incompatible with C++98}}
74 struct { int a; const int &r; } rr = { 0, {{0}} }; // expected-warning {{reference initialized from initializer list is incompatible with C++98}}
Richard Smith6b130222011-10-18 21:39:00 +000075 return { 0 }; // expected-warning {{generalized initializer lists are incompatible with C++98}}
Richard Smith7fe62082011-10-15 05:09:34 +000076}
Sebastian Redlca893712012-03-20 21:24:03 +000077struct DelayedDefaultArgumentParseInitList {
78 void f(int i = {1}) { // expected-warning {{generalized initializer lists are incompatible with C++98}}
79 }
80};
Richard Smith7fe62082011-10-15 05:09:34 +000081
Richard Smith5cc2c6e2012-03-05 04:02:15 +000082int operator"" _hello(const char *); // expected-warning {{literal operators are incompatible with C++98}}
Richard Smith7fe62082011-10-15 05:09:34 +000083
84enum EnumFixed : int { // expected-warning {{enumeration types with a fixed underlying type are incompatible with C++98}}
85};
86
87enum class EnumScoped { // expected-warning {{scoped enumerations are incompatible with C++98}}
88};
89
90void Deleted() = delete; // expected-warning {{deleted function definitions are incompatible with C++98}}
91struct Defaulted {
92 Defaulted() = default; // expected-warning {{defaulted function definitions are incompatible with C++98}}
93};
94
95int &&RvalueReference = 0; // expected-warning {{rvalue references are incompatible with C++98}}
96struct RefQualifier {
97 void f() &; // expected-warning {{reference qualifiers on functions are incompatible with C++98}}
98};
99
100auto f() -> int; // expected-warning {{trailing return types are incompatible with C++98}}
101
102void RangeFor() {
103 int xs[] = {1, 2, 3};
104 for (int &a : xs) { // expected-warning {{range-based for loop is incompatible with C++98}}
105 }
106}
107
108struct InClassInit {
109 int n = 0; // expected-warning {{in-class initialization of non-static data members is incompatible with C++98}}
110};
111
112struct OverrideControlBase {
113 virtual void f();
114 virtual void g();
115};
116struct OverrideControl final : OverrideControlBase { // expected-warning {{'final' keyword is incompatible with C++98}}
117 virtual void f() override; // expected-warning {{'override' keyword is incompatible with C++98}}
118 virtual void g() final; // expected-warning {{'final' keyword is incompatible with C++98}}
119};
120
121using AliasDecl = int; // expected-warning {{alias declarations are incompatible with C++98}}
122template<typename T> using AliasTemplate = T; // expected-warning {{alias declarations are incompatible with C++98}}
123
Richard Smithebaf0e62011-10-18 20:49:44 +0000124inline namespace InlineNS { // expected-warning {{inline namespaces are incompatible with C++98}}
Richard Smith7fe62082011-10-15 05:09:34 +0000125}
Richard Smith0aa86c02011-10-15 05:42:01 +0000126
127auto auto_deduction = 0; // expected-warning {{'auto' type specifier is incompatible with C++98}}
128int *p = new auto(0); // expected-warning {{'auto' type specifier is incompatible with C++98}}
Richard Smith841804b2011-10-17 23:06:20 +0000129
130const int align_of = alignof(int); // expected-warning {{alignof expressions are incompatible with C++98}}
131char16_t c16 = 0; // expected-warning {{'char16_t' type specifier is incompatible with C++98}}
132char32_t c32 = 0; // expected-warning {{'char32_t' type specifier is incompatible with C++98}}
133constexpr int const_expr = 0; // expected-warning {{'constexpr' specifier is incompatible with C++98}}
134decltype(const_expr) decl_type = 0; // expected-warning {{'decltype' type specifier is incompatible with C++98}}
Richard Smith39304fa2012-02-24 18:10:23 +0000135__decltype(const_expr) decl_type2 = 0; // ok
Richard Smith841804b2011-10-17 23:06:20 +0000136void no_except() noexcept; // expected-warning {{noexcept specifications are incompatible with C++98}}
137bool no_except_expr = noexcept(1 + 1); // expected-warning {{noexcept expressions are incompatible with C++98}}
138void *null = nullptr; // expected-warning {{'nullptr' is incompatible with C++98}}
139static_assert(true, "!"); // expected-warning {{static_assert declarations are incompatible with C++98}}
Richard Smithebaf0e62011-10-18 20:49:44 +0000140
141struct InhCtorBase {
142 InhCtorBase(int);
143};
144struct InhCtorDerived : InhCtorBase {
145 using InhCtorBase::InhCtorBase; // expected-warning {{inherited constructors are incompatible with C++98}}
146};
147
148struct FriendMember {
149 static void MemberFn();
150 friend void FriendMember::MemberFn(); // expected-warning {{friend declaration naming a member of the declaring class is incompatible with C++98}}
151};
152
153struct DelegCtor {
154 DelegCtor(int) : DelegCtor() {} // expected-warning {{delegating constructors are incompatible with C++98}}
155 DelegCtor();
156};
157
158template<int n = 0> void DefaultFuncTemplateArg(); // expected-warning {{default template arguments for a function template are incompatible with C++98}}
159
160template<typename T> int TemplateFn(T) { return 0; }
161void LocalTemplateArg() {
162 struct S {};
163 TemplateFn(S()); // expected-warning {{local type 'S' as template argument is incompatible with C++98}}
164}
165struct {} obj_of_unnamed_type; // expected-note {{here}}
166int UnnamedTemplateArg = TemplateFn(obj_of_unnamed_type); // expected-warning {{unnamed type as template argument is incompatible with C++98}}
167
168namespace RedundantParensInAddressTemplateParam {
169 int n;
170 template<int*p> struct S {};
171 S<(&n)> s; // expected-warning {{redundant parentheses surrounding address non-type template argument are incompatible with C++98}}
172 S<(((&n)))> t; // expected-warning {{redundant parentheses surrounding address non-type template argument are incompatible with C++98}}
173}
174
175namespace TemplateSpecOutOfScopeNs {
176 template<typename T> struct S {}; // expected-note {{here}}
177}
178template<> struct TemplateSpecOutOfScopeNs::S<char> {}; // expected-warning {{class template specialization of 'S' outside namespace 'TemplateSpecOutOfScopeNs' is incompatible with C++98}}
179
180struct Typename {
181 template<typename T> struct Inner {};
182};
183typename ::Typename TypenameOutsideTemplate(); // expected-warning {{use of 'typename' outside of a template is incompatible with C++98}}
184Typename::template Inner<int> TemplateOutsideTemplate(); // expected-warning {{use of 'template' keyword outside of a template is incompatible with C++98}}
185
186struct TrivialButNonPOD {
187 int f(int);
188private:
189 int k;
190};
191void Ellipsis(int n, ...);
192void TrivialButNonPODThroughEllipsis() {
193 Ellipsis(1, TrivialButNonPOD()); // expected-warning {{passing object of trivial but non-POD type 'TrivialButNonPOD' through variadic function is incompatible with C++98}}
194}
195
196struct HasExplicitConversion {
197 explicit operator bool(); // expected-warning {{explicit conversion functions are incompatible with C++98}}
198};
Richard Smith6b130222011-10-18 21:39:00 +0000199
200struct Struct {};
201enum Enum { enum_val = 0 };
202struct BadFriends {
203 friend enum ::Enum; // expected-warning {{befriending enumeration type 'enum ::Enum' is incompatible with C++98}}
204 friend int; // expected-warning {{non-class friend type 'int' is incompatible with C++98}}
205 friend Struct; // expected-warning {{befriending 'Struct' without 'struct' keyword is incompatible with C++98}}
206};
207
208int n = {}; // expected-warning {{scalar initialized from empty initializer list is incompatible with C++98}}
Richard Smith77faa362011-10-19 00:07:01 +0000209
210class PrivateMember {
211 struct ImPrivate {};
212};
213template<typename T> typename T::ImPrivate SFINAEAccessControl(T t) { // expected-warning {{substitution failure due to access control is incompatible with C++98}} expected-note {{while substituting deduced template arguments into function template 'SFINAEAccessControl' [with T = PrivateMember]}}
214 return typename T::ImPrivate();
215}
216int SFINAEAccessControl(...) { return 0; }
217int CheckSFINAEAccessControl = SFINAEAccessControl(PrivateMember());
Richard Smith53e53512011-10-19 00:54:10 +0000218
219template<typename T>
220struct FriendRedefinition {
221 friend void Friend() {} // expected-warning {{friend function 'Friend' would be implicitly redefined in C++98}} expected-note {{previous}}
222};
223FriendRedefinition<int> FriendRedef1;
224FriendRedefinition<char> FriendRedef2; // expected-note {{requested here}}
Richard Smith83da2e72011-10-19 16:55:56 +0000225
226namespace CopyCtorIssues {
227 struct Private {
228 Private();
229 private:
230 Private(const Private&); // expected-note {{declared private here}}
231 };
232 struct NoViable {
233 NoViable();
234 NoViable(NoViable&); // expected-note {{not viable}}
235 };
236 struct Ambiguous {
237 Ambiguous();
238 Ambiguous(const Ambiguous &, int = 0); // expected-note {{candidate}}
239 Ambiguous(const Ambiguous &, double = 0); // expected-note {{candidate}}
240 };
Richard Smith6c4c36c2012-03-30 20:53:28 +0000241 struct Deleted {
242 Private p; // expected-note {{implicitly deleted}}
Richard Smith83da2e72011-10-19 16:55:56 +0000243 };
244
245 const Private &a = Private(); // expected-warning {{copying variable of type 'CopyCtorIssues::Private' when binding a reference to a temporary would invoke an inaccessible constructor in C++98}}
246 const NoViable &b = NoViable(); // expected-warning {{copying variable of type 'CopyCtorIssues::NoViable' when binding a reference to a temporary would find no viable constructor in C++98}}
247 const Ambiguous &c = Ambiguous(); // expected-warning {{copying variable of type 'CopyCtorIssues::Ambiguous' when binding a reference to a temporary would find ambiguous constructors in C++98}}
248 const Deleted &d = Deleted(); // expected-warning {{copying variable of type 'CopyCtorIssues::Deleted' when binding a reference to a temporary would invoke a deleted constructor in C++98}}
249}
Richard Smithe7d7c392011-10-19 20:41:51 +0000250
251namespace UnionOrAnonStructMembers {
252 struct NonTrivCtor {
253 NonTrivCtor(); // expected-note 2{{user-declared constructor}}
254 };
255 struct NonTrivCopy {
256 NonTrivCopy(const NonTrivCopy&); // expected-note 2{{user-declared copy constructor}}
257 };
258 struct NonTrivDtor {
259 ~NonTrivDtor(); // expected-note 2{{user-declared destructor}}
260 };
261 union BadUnion {
262 NonTrivCtor ntc; // expected-warning {{union member 'ntc' with a non-trivial constructor is incompatible with C++98}}
263 NonTrivCopy ntcp; // expected-warning {{union member 'ntcp' with a non-trivial copy constructor is incompatible with C++98}}
264 NonTrivDtor ntd; // expected-warning {{union member 'ntd' with a non-trivial destructor is incompatible with C++98}}
265 };
266 struct Wrap {
267 struct {
268 NonTrivCtor ntc; // expected-warning {{anonymous struct member 'ntc' with a non-trivial constructor is incompatible with C++98}}
269 NonTrivCopy ntcp; // expected-warning {{anonymous struct member 'ntcp' with a non-trivial copy constructor is incompatible with C++98}}
270 NonTrivDtor ntd; // expected-warning {{anonymous struct member 'ntd' with a non-trivial destructor is incompatible with C++98}}
271 };
272 };
Richard Smithb9c64d82012-02-16 20:41:22 +0000273 union WithStaticDataMember {
274 static constexpr double d = 0.0; // expected-warning {{static data member 'd' in union is incompatible with C++98}} expected-warning {{'constexpr' specifier is incompatible with C++98}}
275 static const int n = 0; // expected-warning {{static data member 'n' in union is incompatible with C++98}}
276 static int k; // expected-warning {{static data member 'k' in union is incompatible with C++98}}
277 };
Richard Smithe7d7c392011-10-19 20:41:51 +0000278}
Richard Smith95aafb22011-10-20 03:28:47 +0000279
280int EnumNNS = Enum::enum_val; // expected-warning {{enumeration type in nested name specifier is incompatible with C++98}}
281template<typename T> void EnumNNSFn() {
282 int k = T::enum_val; // expected-warning {{enumeration type in nested name specifier is incompatible with C++98}}
283};
284template void EnumNNSFn<Enum>(); // expected-note {{in instantiation}}
Richard Smith0e9e9812011-10-20 21:42:12 +0000285
286void JumpDiagnostics(int n) {
287 goto DirectJump; // expected-warning {{goto would jump into protected scope in C++98}}
288 TrivialButNonPOD tnp1; // expected-note {{jump bypasses initialization of non-POD variable}}
289
290DirectJump:
291 void *Table[] = {&&DirectJump, &&Later};
292 goto *Table[n]; // expected-warning {{indirect goto might cross protected scopes in C++98}}
293
294 TrivialButNonPOD tnp2; // expected-note {{jump bypasses initialization of non-POD variable}}
295Later: // expected-note {{possible target of indirect goto}}
296 switch (n) {
297 TrivialButNonPOD tnp3; // expected-note {{jump bypasses initialization of non-POD variable}}
298 default: // expected-warning {{switch case would be in a protected scope in C++98}}
299 return;
300 }
301}
Richard Smithd390de92012-02-25 10:20:59 +0000302
303namespace UnevaluatedMemberAccess {
304 struct S {
305 int n;
306 int f() { return sizeof(S::n); } // ok
307 };
308 int k = sizeof(S::n); // expected-warning {{use of non-static data member 'n' in an unevaluated context is incompatible with C++98}}
309 const std::type_info &ti = typeid(S::n); // expected-warning {{use of non-static data member 'n' in an unevaluated context is incompatible with C++98}}
310}
Richard Smith26b75c02012-03-09 22:27:51 +0000311
312namespace LiteralUCNs {
313 char c1 = '\u001e'; // expected-warning {{universal character name referring to a control character is incompatible with C++98}}
314 wchar_t c2 = L'\u0041'; // expected-warning {{specifying character 'A' with a universal character name is incompatible with C++98}}
315 const char *s1 = "foo\u0031"; // expected-warning {{specifying character '1' with a universal character name is incompatible with C++98}}
316 const wchar_t *s2 = L"bar\u0085"; // expected-warning {{universal character name referring to a control character is incompatible with C++98}}
317}
Richard Smithb4051e72012-04-04 21:11:30 +0000318
319namespace NonTypeTemplateArgs {
320 template<typename T, T v> struct S {};
321 const int k = 5; // expected-note {{here}}
322 static void f() {} // expected-note {{here}}
323 S<const int&, k> s1; // expected-warning {{non-type template argument referring to object 'k' with internal linkage is incompatible with C++98}}
324 S<void(&)(), f> s2; // expected-warning {{non-type template argument referring to function 'f' with internal linkage is incompatible with C++98}}
325}