blob: 12b95765e0fa8a7c91aa5553a694de3d2fe54f41 [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 Smithd390de92012-02-25 10:20:59 +00004namespace std { struct type_info; }
5
Richard Smith84ef8992011-10-14 20:41:13 +00006template<typename ...T> // expected-warning {{variadic templates are incompatible with C++98}}
7class Variadic1 {};
8
9template<template<typename> class ...T> // expected-warning {{variadic templates are incompatible with C++98}}
10class Variadic2 {};
11
12template<int ...I> // expected-warning {{variadic templates are incompatible with C++98}}
13class Variadic3 {};
Richard Smith41be6732011-10-14 20:48:27 +000014
15int alignas(8) with_alignas; // expected-warning {{'alignas' is incompatible with C++98}}
16int with_attribute [[ ]]; // expected-warning {{attributes are incompatible with C++98}}
Richard Smith661a9962011-10-15 01:18:56 +000017
18void Literals() {
19 (void)u8"str"; // expected-warning {{unicode literals are incompatible with C++98}}
20 (void)u"str"; // expected-warning {{unicode literals are incompatible with C++98}}
21 (void)U"str"; // expected-warning {{unicode literals are incompatible with C++98}}
22 (void)u'x'; // expected-warning {{unicode literals are incompatible with C++98}}
23 (void)U'x'; // expected-warning {{unicode literals are incompatible with C++98}}
24
25 (void)u8R"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}}
26 (void)uR"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}}
27 (void)UR"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}}
28 (void)R"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}}
29 (void)LR"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}}
30}
31
32template<typename T> struct S {};
Richard Smith7fe62082011-10-15 05:09:34 +000033namespace TemplateParsing {
34 S<::S<void> > s; // expected-warning {{'<::' is treated as digraph '<:' (aka '[') followed by ':' in C++98}}
35 S< ::S<void>> t; // expected-warning {{consecutive right angle brackets are incompatible with C++98 (use '> >')}}
36}
37
38void Lambda() {
Richard Smithb9c64d82012-02-16 20:41:22 +000039 []{}(); // expected-warning {{lambda expressions are incompatible with C++98}}
Richard Smith7fe62082011-10-15 05:09:34 +000040}
41
42int InitList() {
Sebastian Redl56a04282012-02-11 23:51:08 +000043 (void)new int {}; // expected-warning {{generalized initializer lists are incompatible with C++98}} \
44 // expected-warning {{scalar initialized from empty initializer list is incompatible with C++98}}
Sebastian Redl6dc00f62012-02-12 18:41:05 +000045 (void)int{}; // expected-warning {{generalized initializer lists are incompatible with C++98}} \
46 // expected-warning {{scalar initialized from empty initializer list is incompatible with C++98}}
Richard Smith6b130222011-10-18 21:39:00 +000047 int x { 0 }; // expected-warning {{generalized initializer lists are incompatible with C++98}}
48 return { 0 }; // expected-warning {{generalized initializer lists are incompatible with C++98}}
Richard Smith7fe62082011-10-15 05:09:34 +000049}
50
51int operator""_hello(const char *); // expected-warning {{literal operators are incompatible with C++98}}
52
53enum EnumFixed : int { // expected-warning {{enumeration types with a fixed underlying type are incompatible with C++98}}
54};
55
56enum class EnumScoped { // expected-warning {{scoped enumerations are incompatible with C++98}}
57};
58
59void Deleted() = delete; // expected-warning {{deleted function definitions are incompatible with C++98}}
60struct Defaulted {
61 Defaulted() = default; // expected-warning {{defaulted function definitions are incompatible with C++98}}
62};
63
64int &&RvalueReference = 0; // expected-warning {{rvalue references are incompatible with C++98}}
65struct RefQualifier {
66 void f() &; // expected-warning {{reference qualifiers on functions are incompatible with C++98}}
67};
68
69auto f() -> int; // expected-warning {{trailing return types are incompatible with C++98}}
70
71void RangeFor() {
72 int xs[] = {1, 2, 3};
73 for (int &a : xs) { // expected-warning {{range-based for loop is incompatible with C++98}}
74 }
75}
76
77struct InClassInit {
78 int n = 0; // expected-warning {{in-class initialization of non-static data members is incompatible with C++98}}
79};
80
81struct OverrideControlBase {
82 virtual void f();
83 virtual void g();
84};
85struct OverrideControl final : OverrideControlBase { // expected-warning {{'final' keyword is incompatible with C++98}}
86 virtual void f() override; // expected-warning {{'override' keyword is incompatible with C++98}}
87 virtual void g() final; // expected-warning {{'final' keyword is incompatible with C++98}}
88};
89
90using AliasDecl = int; // expected-warning {{alias declarations are incompatible with C++98}}
91template<typename T> using AliasTemplate = T; // expected-warning {{alias declarations are incompatible with C++98}}
92
Richard Smithebaf0e62011-10-18 20:49:44 +000093inline namespace InlineNS { // expected-warning {{inline namespaces are incompatible with C++98}}
Richard Smith7fe62082011-10-15 05:09:34 +000094}
Richard Smith0aa86c02011-10-15 05:42:01 +000095
96auto auto_deduction = 0; // expected-warning {{'auto' type specifier is incompatible with C++98}}
97int *p = new auto(0); // expected-warning {{'auto' type specifier is incompatible with C++98}}
Richard Smith841804b2011-10-17 23:06:20 +000098
99const int align_of = alignof(int); // expected-warning {{alignof expressions are incompatible with C++98}}
100char16_t c16 = 0; // expected-warning {{'char16_t' type specifier is incompatible with C++98}}
101char32_t c32 = 0; // expected-warning {{'char32_t' type specifier is incompatible with C++98}}
102constexpr int const_expr = 0; // expected-warning {{'constexpr' specifier is incompatible with C++98}}
103decltype(const_expr) decl_type = 0; // expected-warning {{'decltype' type specifier is incompatible with C++98}}
Richard Smith39304fa2012-02-24 18:10:23 +0000104__decltype(const_expr) decl_type2 = 0; // ok
Richard Smith841804b2011-10-17 23:06:20 +0000105void no_except() noexcept; // expected-warning {{noexcept specifications are incompatible with C++98}}
106bool no_except_expr = noexcept(1 + 1); // expected-warning {{noexcept expressions are incompatible with C++98}}
107void *null = nullptr; // expected-warning {{'nullptr' is incompatible with C++98}}
108static_assert(true, "!"); // expected-warning {{static_assert declarations are incompatible with C++98}}
Richard Smithebaf0e62011-10-18 20:49:44 +0000109
110struct InhCtorBase {
111 InhCtorBase(int);
112};
113struct InhCtorDerived : InhCtorBase {
114 using InhCtorBase::InhCtorBase; // expected-warning {{inherited constructors are incompatible with C++98}}
115};
116
117struct FriendMember {
118 static void MemberFn();
119 friend void FriendMember::MemberFn(); // expected-warning {{friend declaration naming a member of the declaring class is incompatible with C++98}}
120};
121
122struct DelegCtor {
123 DelegCtor(int) : DelegCtor() {} // expected-warning {{delegating constructors are incompatible with C++98}}
124 DelegCtor();
125};
126
127template<int n = 0> void DefaultFuncTemplateArg(); // expected-warning {{default template arguments for a function template are incompatible with C++98}}
128
129template<typename T> int TemplateFn(T) { return 0; }
130void LocalTemplateArg() {
131 struct S {};
132 TemplateFn(S()); // expected-warning {{local type 'S' as template argument is incompatible with C++98}}
133}
134struct {} obj_of_unnamed_type; // expected-note {{here}}
135int UnnamedTemplateArg = TemplateFn(obj_of_unnamed_type); // expected-warning {{unnamed type as template argument is incompatible with C++98}}
136
137namespace RedundantParensInAddressTemplateParam {
138 int n;
139 template<int*p> struct S {};
140 S<(&n)> s; // expected-warning {{redundant parentheses surrounding address non-type template argument are incompatible with C++98}}
141 S<(((&n)))> t; // expected-warning {{redundant parentheses surrounding address non-type template argument are incompatible with C++98}}
142}
143
144namespace TemplateSpecOutOfScopeNs {
145 template<typename T> struct S {}; // expected-note {{here}}
146}
147template<> struct TemplateSpecOutOfScopeNs::S<char> {}; // expected-warning {{class template specialization of 'S' outside namespace 'TemplateSpecOutOfScopeNs' is incompatible with C++98}}
148
149struct Typename {
150 template<typename T> struct Inner {};
151};
152typename ::Typename TypenameOutsideTemplate(); // expected-warning {{use of 'typename' outside of a template is incompatible with C++98}}
153Typename::template Inner<int> TemplateOutsideTemplate(); // expected-warning {{use of 'template' keyword outside of a template is incompatible with C++98}}
154
155struct TrivialButNonPOD {
156 int f(int);
157private:
158 int k;
159};
160void Ellipsis(int n, ...);
161void TrivialButNonPODThroughEllipsis() {
162 Ellipsis(1, TrivialButNonPOD()); // expected-warning {{passing object of trivial but non-POD type 'TrivialButNonPOD' through variadic function is incompatible with C++98}}
163}
164
165struct HasExplicitConversion {
166 explicit operator bool(); // expected-warning {{explicit conversion functions are incompatible with C++98}}
167};
Richard Smith6b130222011-10-18 21:39:00 +0000168
169struct Struct {};
170enum Enum { enum_val = 0 };
171struct BadFriends {
172 friend enum ::Enum; // expected-warning {{befriending enumeration type 'enum ::Enum' is incompatible with C++98}}
173 friend int; // expected-warning {{non-class friend type 'int' is incompatible with C++98}}
174 friend Struct; // expected-warning {{befriending 'Struct' without 'struct' keyword is incompatible with C++98}}
175};
176
177int n = {}; // expected-warning {{scalar initialized from empty initializer list is incompatible with C++98}}
Richard Smith77faa362011-10-19 00:07:01 +0000178
179class PrivateMember {
180 struct ImPrivate {};
181};
182template<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]}}
183 return typename T::ImPrivate();
184}
185int SFINAEAccessControl(...) { return 0; }
186int CheckSFINAEAccessControl = SFINAEAccessControl(PrivateMember());
Richard Smith53e53512011-10-19 00:54:10 +0000187
188template<typename T>
189struct FriendRedefinition {
190 friend void Friend() {} // expected-warning {{friend function 'Friend' would be implicitly redefined in C++98}} expected-note {{previous}}
191};
192FriendRedefinition<int> FriendRedef1;
193FriendRedefinition<char> FriendRedef2; // expected-note {{requested here}}
Richard Smith83da2e72011-10-19 16:55:56 +0000194
195namespace CopyCtorIssues {
196 struct Private {
197 Private();
198 private:
199 Private(const Private&); // expected-note {{declared private here}}
200 };
201 struct NoViable {
202 NoViable();
203 NoViable(NoViable&); // expected-note {{not viable}}
204 };
205 struct Ambiguous {
206 Ambiguous();
207 Ambiguous(const Ambiguous &, int = 0); // expected-note {{candidate}}
208 Ambiguous(const Ambiguous &, double = 0); // expected-note {{candidate}}
209 };
210 struct Deleted { // expected-note {{here}}
211 // Copy ctor implicitly defined as deleted because Private's copy ctor is
212 // inaccessible.
213 Private p;
214 };
215
216 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}}
217 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}}
218 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}}
219 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}}
220}
Richard Smithe7d7c392011-10-19 20:41:51 +0000221
222namespace UnionOrAnonStructMembers {
223 struct NonTrivCtor {
224 NonTrivCtor(); // expected-note 2{{user-declared constructor}}
225 };
226 struct NonTrivCopy {
227 NonTrivCopy(const NonTrivCopy&); // expected-note 2{{user-declared copy constructor}}
228 };
229 struct NonTrivDtor {
230 ~NonTrivDtor(); // expected-note 2{{user-declared destructor}}
231 };
232 union BadUnion {
233 NonTrivCtor ntc; // expected-warning {{union member 'ntc' with a non-trivial constructor is incompatible with C++98}}
234 NonTrivCopy ntcp; // expected-warning {{union member 'ntcp' with a non-trivial copy constructor is incompatible with C++98}}
235 NonTrivDtor ntd; // expected-warning {{union member 'ntd' with a non-trivial destructor is incompatible with C++98}}
236 };
237 struct Wrap {
238 struct {
239 NonTrivCtor ntc; // expected-warning {{anonymous struct member 'ntc' with a non-trivial constructor is incompatible with C++98}}
240 NonTrivCopy ntcp; // expected-warning {{anonymous struct member 'ntcp' with a non-trivial copy constructor is incompatible with C++98}}
241 NonTrivDtor ntd; // expected-warning {{anonymous struct member 'ntd' with a non-trivial destructor is incompatible with C++98}}
242 };
243 };
Richard Smithb9c64d82012-02-16 20:41:22 +0000244 union WithStaticDataMember {
245 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}}
246 static const int n = 0; // expected-warning {{static data member 'n' in union is incompatible with C++98}}
247 static int k; // expected-warning {{static data member 'k' in union is incompatible with C++98}}
248 };
Richard Smithe7d7c392011-10-19 20:41:51 +0000249}
Richard Smith95aafb22011-10-20 03:28:47 +0000250
251int EnumNNS = Enum::enum_val; // expected-warning {{enumeration type in nested name specifier is incompatible with C++98}}
252template<typename T> void EnumNNSFn() {
253 int k = T::enum_val; // expected-warning {{enumeration type in nested name specifier is incompatible with C++98}}
254};
255template void EnumNNSFn<Enum>(); // expected-note {{in instantiation}}
Richard Smith0e9e9812011-10-20 21:42:12 +0000256
257void JumpDiagnostics(int n) {
258 goto DirectJump; // expected-warning {{goto would jump into protected scope in C++98}}
259 TrivialButNonPOD tnp1; // expected-note {{jump bypasses initialization of non-POD variable}}
260
261DirectJump:
262 void *Table[] = {&&DirectJump, &&Later};
263 goto *Table[n]; // expected-warning {{indirect goto might cross protected scopes in C++98}}
264
265 TrivialButNonPOD tnp2; // expected-note {{jump bypasses initialization of non-POD variable}}
266Later: // expected-note {{possible target of indirect goto}}
267 switch (n) {
268 TrivialButNonPOD tnp3; // expected-note {{jump bypasses initialization of non-POD variable}}
269 default: // expected-warning {{switch case would be in a protected scope in C++98}}
270 return;
271 }
272}
Richard Smithd390de92012-02-25 10:20:59 +0000273
274namespace UnevaluatedMemberAccess {
275 struct S {
276 int n;
277 int f() { return sizeof(S::n); } // ok
278 };
279 int k = sizeof(S::n); // expected-warning {{use of non-static data member 'n' in an unevaluated context is incompatible with C++98}}
280 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}}
281}