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