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