1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s
3
4 namespace std { struct type_info; }
5
6 template<typename ...T> // expected-warning {{variadic templates are incompatible with C++98}}
7 class Variadic1 {};
8
9 template<template<typename> class ...T> // expected-warning {{variadic templates are incompatible with C++98}}
10 class Variadic2 {};
11
12 template<int ...I> // expected-warning {{variadic templates are incompatible with C++98}}
13 class Variadic3 {};
14
15 int alignas(8) with_alignas; // expected-warning {{'alignas' is incompatible with C++98}}
16 int with_attribute [[ ]]; // expected-warning {{attributes are incompatible with C++98}}
17
Literals()18 void 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
32 template<typename T> struct S {};
33 namespace 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
Lambda()38 void Lambda() {
39 []{}(); // expected-warning {{lambda expressions are incompatible with C++98}}
40 }
41
InitList(int i={})42 int InitList(int i = {}) { // expected-warning {{generalized initializer lists are incompatible with C++98}} \
43 // expected-warning {{scalar initialized from empty initializer list is incompatible with C++98}}
44 (void)new int {}; // expected-warning {{generalized initializer lists are incompatible with C++98}} \
45 // expected-warning {{scalar initialized from empty initializer list is incompatible with C++98}}
46 (void)int{}; // expected-warning {{generalized initializer lists are incompatible with C++98}} \
47 // expected-warning {{scalar initialized from empty initializer list is incompatible with C++98}}
48 int x { 0 }; // expected-warning {{generalized initializer lists are incompatible with C++98}}
49 S<int> s = {}; // ok, aggregate
50 s = {}; // expected-warning {{generalized initializer lists are incompatible with C++98}}
51 return { 0 }; // expected-warning {{generalized initializer lists are incompatible with C++98}}
52 }
53 struct DelayedDefaultArgumentParseInitList {
fDelayedDefaultArgumentParseInitList54 void f(int i = {1}) { // expected-warning {{generalized initializer lists are incompatible with C++98}}
55 }
56 };
57
58 int operator"" _hello(const char *); // expected-warning {{literal operators are incompatible with C++98}}
59
60 enum EnumFixed : int { // expected-warning {{enumeration types with a fixed underlying type are incompatible with C++98}}
61 };
62
63 enum class EnumScoped { // expected-warning {{scoped enumerations are incompatible with C++98}}
64 };
65
66 void Deleted() = delete; // expected-warning {{deleted function definitions are incompatible with C++98}}
67 struct Defaulted {
68 Defaulted() = default; // expected-warning {{defaulted function definitions are incompatible with C++98}}
69 };
70
71 int &&RvalueReference = 0; // expected-warning {{rvalue references are incompatible with C++98}}
72 struct RefQualifier {
73 void f() &; // expected-warning {{reference qualifiers on functions are incompatible with C++98}}
74 };
75
76 auto f() -> int; // expected-warning {{trailing return types are incompatible with C++98}}
77
RangeFor()78 void RangeFor() {
79 int xs[] = {1, 2, 3};
80 for (int &a : xs) { // expected-warning {{range-based for loop is incompatible with C++98}}
81 }
82 }
83
84 struct InClassInit {
85 int n = 0; // expected-warning {{in-class initialization of non-static data members is incompatible with C++98}}
86 };
87
88 struct OverrideControlBase {
89 virtual void f();
90 virtual void g();
91 };
92 struct OverrideControl final : OverrideControlBase { // expected-warning {{'final' keyword is incompatible with C++98}}
93 virtual void f() override; // expected-warning {{'override' keyword is incompatible with C++98}}
94 virtual void g() final; // expected-warning {{'final' keyword is incompatible with C++98}}
95 };
96
97 using AliasDecl = int; // expected-warning {{alias declarations are incompatible with C++98}}
98 template<typename T> using AliasTemplate = T; // expected-warning {{alias declarations are incompatible with C++98}}
99
100 inline namespace InlineNS { // expected-warning {{inline namespaces are incompatible with C++98}}
101 }
102
103 auto auto_deduction = 0; // expected-warning {{'auto' type specifier is incompatible with C++98}}
104 int *p = new auto(0); // expected-warning {{'auto' type specifier is incompatible with C++98}}
105
106 const int align_of = alignof(int); // expected-warning {{alignof expressions are incompatible with C++98}}
107 char16_t c16 = 0; // expected-warning {{'char16_t' type specifier is incompatible with C++98}}
108 char32_t c32 = 0; // expected-warning {{'char32_t' type specifier is incompatible with C++98}}
109 constexpr int const_expr = 0; // expected-warning {{'constexpr' specifier is incompatible with C++98}}
110 decltype(const_expr) decl_type = 0; // expected-warning {{'decltype' type specifier is incompatible with C++98}}
111 __decltype(const_expr) decl_type2 = 0; // ok
112 void no_except() noexcept; // expected-warning {{noexcept specifications are incompatible with C++98}}
113 bool no_except_expr = noexcept(1 + 1); // expected-warning {{noexcept expressions are incompatible with C++98}}
114 void *null = nullptr; // expected-warning {{'nullptr' is incompatible with C++98}}
115 static_assert(true, "!"); // expected-warning {{static_assert declarations are incompatible with C++98}}
116
117 struct InhCtorBase {
118 InhCtorBase(int);
119 };
120 struct InhCtorDerived : InhCtorBase {
121 using InhCtorBase::InhCtorBase; // expected-warning {{inherited constructors are incompatible with C++98}}
122 };
123
124 struct FriendMember {
125 static void MemberFn();
126 friend void FriendMember::MemberFn(); // expected-warning {{friend declaration naming a member of the declaring class is incompatible with C++98}}
127 };
128
129 struct DelegCtor {
DelegCtorDelegCtor130 DelegCtor(int) : DelegCtor() {} // expected-warning {{delegating constructors are incompatible with C++98}}
131 DelegCtor();
132 };
133
134 template<int n = 0> void DefaultFuncTemplateArg(); // expected-warning {{default template arguments for a function template are incompatible with C++98}}
135
TemplateFn(T)136 template<typename T> int TemplateFn(T) { return 0; }
LocalTemplateArg()137 void LocalTemplateArg() {
138 struct S {};
139 TemplateFn(S()); // expected-warning {{local type 'S' as template argument is incompatible with C++98}}
140 }
141 struct {} obj_of_unnamed_type; // expected-note {{here}}
142 int UnnamedTemplateArg = TemplateFn(obj_of_unnamed_type); // expected-warning {{unnamed type as template argument is incompatible with C++98}}
143
144 namespace RedundantParensInAddressTemplateParam {
145 int n;
146 template<int*p> struct S {};
147 S<(&n)> s; // expected-warning {{redundant parentheses surrounding address non-type template argument are incompatible with C++98}}
148 S<(((&n)))> t; // expected-warning {{redundant parentheses surrounding address non-type template argument are incompatible with C++98}}
149 }
150
151 namespace TemplateSpecOutOfScopeNs {
152 template<typename T> struct S {}; // expected-note {{here}}
153 }
154 template<> struct TemplateSpecOutOfScopeNs::S<char> {}; // expected-warning {{class template specialization of 'S' outside namespace 'TemplateSpecOutOfScopeNs' is incompatible with C++98}}
155
156 struct Typename {
157 template<typename T> struct Inner {};
158 };
159 typename ::Typename TypenameOutsideTemplate(); // expected-warning {{use of 'typename' outside of a template is incompatible with C++98}}
160 Typename::template Inner<int> TemplateOutsideTemplate(); // expected-warning {{use of 'template' keyword outside of a template is incompatible with C++98}}
161
162 struct TrivialButNonPOD {
163 int f(int);
164 private:
165 int k;
166 };
167 void Ellipsis(int n, ...);
TrivialButNonPODThroughEllipsis()168 void TrivialButNonPODThroughEllipsis() {
169 Ellipsis(1, TrivialButNonPOD()); // expected-warning {{passing object of trivial but non-POD type 'TrivialButNonPOD' through variadic function is incompatible with C++98}}
170 }
171
172 struct HasExplicitConversion {
173 explicit operator bool(); // expected-warning {{explicit conversion functions are incompatible with C++98}}
174 };
175
176 struct Struct {};
177 enum Enum { enum_val = 0 };
178 struct BadFriends {
179 friend enum ::Enum; // expected-warning {{befriending enumeration type 'enum ::Enum' is incompatible with C++98}}
180 friend int; // expected-warning {{non-class friend type 'int' is incompatible with C++98}}
181 friend Struct; // expected-warning {{befriending 'Struct' without 'struct' keyword is incompatible with C++98}}
182 };
183
184 int n = {}; // expected-warning {{scalar initialized from empty initializer list is incompatible with C++98}}
185
186 class PrivateMember {
187 struct ImPrivate {};
188 };
SFINAEAccessControl(T t)189 template<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]}}
190 return typename T::ImPrivate();
191 }
SFINAEAccessControl(...)192 int SFINAEAccessControl(...) { return 0; }
193 int CheckSFINAEAccessControl = SFINAEAccessControl(PrivateMember());
194
195 template<typename T>
196 struct FriendRedefinition {
Friend()197 friend void Friend() {} // expected-warning {{friend function 'Friend' would be implicitly redefined in C++98}} expected-note {{previous}}
198 };
199 FriendRedefinition<int> FriendRedef1;
200 FriendRedefinition<char> FriendRedef2; // expected-note {{requested here}}
201
202 namespace CopyCtorIssues {
203 struct Private {
204 Private();
205 private:
206 Private(const Private&); // expected-note {{declared private here}}
207 };
208 struct NoViable {
209 NoViable();
210 NoViable(NoViable&); // expected-note {{not viable}}
211 };
212 struct Ambiguous {
213 Ambiguous();
214 Ambiguous(const Ambiguous &, int = 0); // expected-note {{candidate}}
215 Ambiguous(const Ambiguous &, double = 0); // expected-note {{candidate}}
216 };
217 struct Deleted {
218 Private p; // expected-note {{implicitly deleted}}
219 };
220
221 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}}
222 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}}
223 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}}
224 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}}
225 }
226
227 namespace UnionOrAnonStructMembers {
228 struct NonTrivCtor {
229 NonTrivCtor(); // expected-note 2{{user-declared constructor}}
230 };
231 struct NonTrivCopy {
232 NonTrivCopy(const NonTrivCopy&); // expected-note 2{{user-declared copy constructor}}
233 };
234 struct NonTrivDtor {
235 ~NonTrivDtor(); // expected-note 2{{user-declared destructor}}
236 };
237 union BadUnion {
238 NonTrivCtor ntc; // expected-warning {{union member 'ntc' with a non-trivial constructor is incompatible with C++98}}
239 NonTrivCopy ntcp; // expected-warning {{union member 'ntcp' with a non-trivial copy constructor is incompatible with C++98}}
240 NonTrivDtor ntd; // expected-warning {{union member 'ntd' with a non-trivial destructor is incompatible with C++98}}
241 };
242 struct Wrap {
243 struct {
244 NonTrivCtor ntc; // expected-warning {{anonymous struct member 'ntc' with a non-trivial constructor is incompatible with C++98}}
245 NonTrivCopy ntcp; // expected-warning {{anonymous struct member 'ntcp' with a non-trivial copy constructor is incompatible with C++98}}
246 NonTrivDtor ntd; // expected-warning {{anonymous struct member 'ntd' with a non-trivial destructor is incompatible with C++98}}
247 };
248 };
249 union WithStaticDataMember {
250 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}}
251 static const int n = 0; // expected-warning {{static data member 'n' in union is incompatible with C++98}}
252 static int k; // expected-warning {{static data member 'k' in union is incompatible with C++98}}
253 };
254 }
255
256 int EnumNNS = Enum::enum_val; // expected-warning {{enumeration type in nested name specifier is incompatible with C++98}}
EnumNNSFn()257 template<typename T> void EnumNNSFn() {
258 int k = T::enum_val; // expected-warning {{enumeration type in nested name specifier is incompatible with C++98}}
259 };
260 template void EnumNNSFn<Enum>(); // expected-note {{in instantiation}}
261
JumpDiagnostics(int n)262 void JumpDiagnostics(int n) {
263 goto DirectJump; // expected-warning {{goto would jump into protected scope in C++98}}
264 TrivialButNonPOD tnp1; // expected-note {{jump bypasses initialization of non-POD variable}}
265
266 DirectJump:
267 void *Table[] = {&&DirectJump, &&Later};
268 goto *Table[n]; // expected-warning {{indirect goto might cross protected scopes in C++98}}
269
270 TrivialButNonPOD tnp2; // expected-note {{jump bypasses initialization of non-POD variable}}
271 Later: // expected-note {{possible target of indirect goto}}
272 switch (n) {
273 TrivialButNonPOD tnp3; // expected-note {{jump bypasses initialization of non-POD variable}}
274 default: // expected-warning {{switch case would be in a protected scope in C++98}}
275 return;
276 }
277 }
278
279 namespace UnevaluatedMemberAccess {
280 struct S {
281 int n;
fUnevaluatedMemberAccess::S282 int f() { return sizeof(S::n); } // ok
283 };
284 int k = sizeof(S::n); // expected-warning {{use of non-static data member 'n' in an unevaluated context is incompatible with C++98}}
285 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}}
286 }
287
288 namespace LiteralUCNs {
289 char c1 = '\u001e'; // expected-warning {{universal character name referring to a control character is incompatible with C++98}}
290 wchar_t c2 = L'\u0041'; // expected-warning {{specifying character 'A' with a universal character name is incompatible with C++98}}
291 const char *s1 = "foo\u0031"; // expected-warning {{specifying character '1' with a universal character name is incompatible with C++98}}
292 const wchar_t *s2 = L"bar\u0085"; // expected-warning {{universal character name referring to a control character is incompatible with C++98}}
293 }
294
295 namespace NonTypeTemplateArgs {
296 template<typename T, T v> struct S {};
297 const int k = 5; // expected-note {{here}}
f()298 static void f() {} // expected-note {{here}}
299 S<const int&, k> s1; // expected-warning {{non-type template argument referring to object 'k' with internal linkage is incompatible with C++98}}
300 S<void(&)(), f> s2; // expected-warning {{non-type template argument referring to function 'f' with internal linkage is incompatible with C++98}}
301 }
302