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