| Richard Smith | f679b5b | 2011-10-14 20:48:27 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wc++98-compat -verify %s |
| Nico Weber | acb35c0 | 2014-09-18 02:09:53 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -fsyntax-only -std=c++14 -Wc++98-compat -verify %s -DCXX14COMPAT |
| Richard Smith | 2b6b0ee | 2011-10-14 20:41:13 +0000 | [diff] [blame] | 3 | |
| Richard Smith | 2b349ae | 2012-04-19 06:58:00 +0000 | [diff] [blame] | 4 | namespace std { |
| 5 | struct type_info; |
| 6 | using size_t = decltype(sizeof(0)); // expected-warning {{decltype}} expected-warning {{alias}} |
| 7 | template<typename T> struct initializer_list { |
| 8 | initializer_list(T*, size_t); |
| 9 | T *p; |
| 10 | size_t n; |
| Richard Smith | a7edaad | 2013-01-12 01:05:20 +0000 | [diff] [blame] | 11 | T *begin(); |
| 12 | T *end(); |
| Richard Smith | 2b349ae | 2012-04-19 06:58:00 +0000 | [diff] [blame] | 13 | }; |
| 14 | } |
| Richard Smith | 2a98611 | 2012-02-25 10:20:59 +0000 | [diff] [blame] | 15 | |
| Richard Smith | 2b6b0ee | 2011-10-14 20:41:13 +0000 | [diff] [blame] | 16 | template<typename ...T> // expected-warning {{variadic templates are incompatible with C++98}} |
| 17 | class Variadic1 {}; |
| 18 | |
| 19 | template<template<typename> class ...T> // expected-warning {{variadic templates are incompatible with C++98}} |
| 20 | class Variadic2 {}; |
| 21 | |
| 22 | template<int ...I> // expected-warning {{variadic templates are incompatible with C++98}} |
| 23 | class Variadic3 {}; |
| Richard Smith | f679b5b | 2011-10-14 20:48:27 +0000 | [diff] [blame] | 24 | |
| Michael Han | 64536a6 | 2012-11-06 19:34:54 +0000 | [diff] [blame] | 25 | alignas(8) int with_alignas; // expected-warning {{'alignas' is incompatible with C++98}} |
| Richard Smith | 3dd73db | 2014-01-17 00:11:48 +0000 | [diff] [blame] | 26 | int with_attribute [[ ]]; // expected-warning {{C++11 attribute syntax is incompatible with C++98}} |
| Richard Smith | acd4d3d | 2011-10-15 01:18:56 +0000 | [diff] [blame] | 27 | |
| 28 | void Literals() { |
| 29 | (void)u8"str"; // expected-warning {{unicode literals are incompatible with C++98}} |
| 30 | (void)u"str"; // expected-warning {{unicode literals are incompatible with C++98}} |
| 31 | (void)U"str"; // expected-warning {{unicode literals are incompatible with C++98}} |
| 32 | (void)u'x'; // expected-warning {{unicode literals are incompatible with C++98}} |
| 33 | (void)U'x'; // expected-warning {{unicode literals are incompatible with C++98}} |
| 34 | |
| 35 | (void)u8R"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}} |
| 36 | (void)uR"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}} |
| 37 | (void)UR"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}} |
| 38 | (void)R"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}} |
| 39 | (void)LR"X(str)X"; // expected-warning {{raw string literals are incompatible with C++98}} |
| 40 | } |
| 41 | |
| 42 | template<typename T> struct S {}; |
| Richard Smith | 5d164bc | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 43 | namespace TemplateParsing { |
| 44 | S<::S<void> > s; // expected-warning {{'<::' is treated as digraph '<:' (aka '[') followed by ':' in C++98}} |
| 45 | S< ::S<void>> t; // expected-warning {{consecutive right angle brackets are incompatible with C++98 (use '> >')}} |
| 46 | } |
| 47 | |
| 48 | void Lambda() { |
| Richard Smith | 4297375 | 2012-02-16 20:41:22 +0000 | [diff] [blame] | 49 | []{}(); // expected-warning {{lambda expressions are incompatible with C++98}} |
| Richard Smith | 5d164bc | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| Richard Smith | 2b349ae | 2012-04-19 06:58:00 +0000 | [diff] [blame] | 52 | struct Ctor { |
| 53 | Ctor(int, char); |
| 54 | Ctor(double, long); |
| 55 | }; |
| 56 | struct InitListCtor { |
| 57 | InitListCtor(std::initializer_list<bool>); |
| 58 | }; |
| 59 | |
| Sebastian Redl | 1678d5f | 2012-03-18 22:25:45 +0000 | [diff] [blame] | 60 | int InitList(int i = {}) { // expected-warning {{generalized initializer lists are incompatible with C++98}} \ |
| 61 | // expected-warning {{scalar initialized from empty initializer list is incompatible with C++98}} |
| Sebastian Redl | 82ace98 | 2012-02-11 23:51:08 +0000 | [diff] [blame] | 62 | (void)new int {}; // expected-warning {{generalized initializer lists are incompatible with C++98}} \ |
| 63 | // expected-warning {{scalar initialized from empty initializer list is incompatible with C++98}} |
| Sebastian Redl | d74dd49 | 2012-02-12 18:41:05 +0000 | [diff] [blame] | 64 | (void)int{}; // expected-warning {{generalized initializer lists are incompatible with C++98}} \ |
| 65 | // expected-warning {{scalar initialized from empty initializer list is incompatible with C++98}} |
| Richard Smith | c823973 | 2011-10-18 21:39:00 +0000 | [diff] [blame] | 66 | int x { 0 }; // expected-warning {{generalized initializer lists are incompatible with C++98}} |
| Richard Smith | 2fbb3d8 | 2012-02-26 23:49:01 +0000 | [diff] [blame] | 67 | S<int> s = {}; // ok, aggregate |
| 68 | s = {}; // expected-warning {{generalized initializer lists are incompatible with C++98}} |
| Richard Smith | 2b349ae | 2012-04-19 06:58:00 +0000 | [diff] [blame] | 69 | std::initializer_list<int> xs = { 1, 2, 3 }; // expected-warning {{initialization of initializer_list object is incompatible with C++98}} |
| 70 | auto ys = { 1, 2, 3 }; // expected-warning {{initialization of initializer_list object is incompatible with C++98}} \ |
| 71 | // expected-warning {{'auto' type specifier is incompatible with C++98}} |
| 72 | Ctor c1 = { 1, 2 }; // expected-warning {{constructor call from initializer list is incompatible with C++98}} |
| 73 | Ctor c2 = { 3.0, 4l }; // expected-warning {{constructor call from initializer list is incompatible with C++98}} |
| 74 | InitListCtor ilc = { true, false }; // expected-warning {{initialization of initializer_list object is incompatible with C++98}} |
| 75 | const int &r = { 0 }; // expected-warning {{reference initialized from initializer list is incompatible with C++98}} |
| Richard Smith | 72752e8 | 2013-05-31 02:56:17 +0000 | [diff] [blame] | 76 | struct { int a; const int &r; } rr = { 0, {0} }; // expected-warning {{reference initialized from initializer list is incompatible with C++98}} |
| Richard Smith | c823973 | 2011-10-18 21:39:00 +0000 | [diff] [blame] | 77 | return { 0 }; // expected-warning {{generalized initializer lists are incompatible with C++98}} |
| Richard Smith | 5d164bc | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 78 | } |
| Sebastian Redl | 6db0b1b | 2012-03-20 21:24:03 +0000 | [diff] [blame] | 79 | struct DelayedDefaultArgumentParseInitList { |
| 80 | void f(int i = {1}) { // expected-warning {{generalized initializer lists are incompatible with C++98}} |
| 81 | } |
| 82 | }; |
| Richard Smith | 5d164bc | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 83 | |
| Richard Smith | e18f0fa | 2012-03-05 04:02:15 +0000 | [diff] [blame] | 84 | int operator"" _hello(const char *); // expected-warning {{literal operators are incompatible with C++98}} |
| Richard Smith | 5d164bc | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 85 | |
| 86 | enum EnumFixed : int { // expected-warning {{enumeration types with a fixed underlying type are incompatible with C++98}} |
| 87 | }; |
| 88 | |
| 89 | enum class EnumScoped { // expected-warning {{scoped enumerations are incompatible with C++98}} |
| 90 | }; |
| 91 | |
| 92 | void Deleted() = delete; // expected-warning {{deleted function definitions are incompatible with C++98}} |
| 93 | struct Defaulted { |
| 94 | Defaulted() = default; // expected-warning {{defaulted function definitions are incompatible with C++98}} |
| 95 | }; |
| 96 | |
| 97 | int &&RvalueReference = 0; // expected-warning {{rvalue references are incompatible with C++98}} |
| 98 | struct RefQualifier { |
| 99 | void f() &; // expected-warning {{reference qualifiers on functions are incompatible with C++98}} |
| 100 | }; |
| 101 | |
| 102 | auto f() -> int; // expected-warning {{trailing return types are incompatible with C++98}} |
| 103 | |
| 104 | void RangeFor() { |
| 105 | int xs[] = {1, 2, 3}; |
| 106 | for (int &a : xs) { // expected-warning {{range-based for loop is incompatible with C++98}} |
| 107 | } |
| Richard Smith | a7edaad | 2013-01-12 01:05:20 +0000 | [diff] [blame] | 108 | for (auto &b : {1, 2, 3}) { |
| 109 | // expected-warning@-1 {{range-based for loop is incompatible with C++98}} |
| 110 | // expected-warning@-2 {{'auto' type specifier is incompatible with C++98}} |
| 111 | // expected-warning@-3 {{initialization of initializer_list object is incompatible with C++98}} |
| Richard Smith | d0c842d | 2013-01-26 00:39:02 +0000 | [diff] [blame] | 112 | // expected-warning@-4 {{reference initialized from initializer list is incompatible with C++98}} |
| Richard Smith | a7edaad | 2013-01-12 01:05:20 +0000 | [diff] [blame] | 113 | } |
| Richard Smith | d0c842d | 2013-01-26 00:39:02 +0000 | [diff] [blame] | 114 | struct Agg { int a, b; } const &agg = { 1, 2 }; // expected-warning {{reference initialized from initializer list is incompatible with C++98}} |
| Richard Smith | 5d164bc | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | struct InClassInit { |
| 118 | int n = 0; // expected-warning {{in-class initialization of non-static data members is incompatible with C++98}} |
| 119 | }; |
| 120 | |
| 121 | struct OverrideControlBase { |
| 122 | virtual void f(); |
| Alexander Potapenko | e2e8b0e | 2014-10-03 09:02:53 +0000 | [diff] [blame] | 123 | virtual void g(); |
| Richard Smith | 5d164bc | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 124 | }; |
| 125 | struct OverrideControl final : OverrideControlBase { // expected-warning {{'final' keyword is incompatible with C++98}} |
| 126 | virtual void f() override; // expected-warning {{'override' keyword is incompatible with C++98}} |
| Alexander Potapenko | e2e8b0e | 2014-10-03 09:02:53 +0000 | [diff] [blame] | 127 | virtual void g() final; // expected-warning {{'final' keyword is incompatible with C++98}} |
| Richard Smith | 5d164bc | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | using AliasDecl = int; // expected-warning {{alias declarations are incompatible with C++98}} |
| 131 | template<typename T> using AliasTemplate = T; // expected-warning {{alias declarations are incompatible with C++98}} |
| 132 | |
| Richard Smith | 0bf8a492 | 2011-10-18 20:49:44 +0000 | [diff] [blame] | 133 | inline namespace InlineNS { // expected-warning {{inline namespaces are incompatible with C++98}} |
| Richard Smith | 5d164bc | 2011-10-15 05:09:34 +0000 | [diff] [blame] | 134 | } |
| Richard Smith | e41fac2 | 2011-10-15 05:42:01 +0000 | [diff] [blame] | 135 | |
| 136 | auto auto_deduction = 0; // expected-warning {{'auto' type specifier is incompatible with C++98}} |
| 137 | int *p = new auto(0); // expected-warning {{'auto' type specifier is incompatible with C++98}} |
| Richard Smith | b15c11c | 2011-10-17 23:06:20 +0000 | [diff] [blame] | 138 | |
| 139 | const int align_of = alignof(int); // expected-warning {{alignof expressions are incompatible with C++98}} |
| 140 | char16_t c16 = 0; // expected-warning {{'char16_t' type specifier is incompatible with C++98}} |
| 141 | char32_t c32 = 0; // expected-warning {{'char32_t' type specifier is incompatible with C++98}} |
| 142 | constexpr int const_expr = 0; // expected-warning {{'constexpr' specifier is incompatible with C++98}} |
| 143 | decltype(const_expr) decl_type = 0; // expected-warning {{'decltype' type specifier is incompatible with C++98}} |
| Richard Smith | fd3da93 | 2012-02-24 18:10:23 +0000 | [diff] [blame] | 144 | __decltype(const_expr) decl_type2 = 0; // ok |
| Richard Smith | b15c11c | 2011-10-17 23:06:20 +0000 | [diff] [blame] | 145 | void no_except() noexcept; // expected-warning {{noexcept specifications are incompatible with C++98}} |
| 146 | bool no_except_expr = noexcept(1 + 1); // expected-warning {{noexcept expressions are incompatible with C++98}} |
| 147 | void *null = nullptr; // expected-warning {{'nullptr' is incompatible with C++98}} |
| 148 | static_assert(true, "!"); // expected-warning {{static_assert declarations are incompatible with C++98}} |
| Richard Smith | 0bf8a492 | 2011-10-18 20:49:44 +0000 | [diff] [blame] | 149 | |
| 150 | struct InhCtorBase { |
| 151 | InhCtorBase(int); |
| 152 | }; |
| 153 | struct InhCtorDerived : InhCtorBase { |
| Richard Smith | 070a5d6 | 2013-07-20 19:22:08 +0000 | [diff] [blame] | 154 | using InhCtorBase::InhCtorBase; // expected-warning {{inheriting constructors are incompatible with C++98}} |
| Richard Smith | 0bf8a492 | 2011-10-18 20:49:44 +0000 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | struct FriendMember { |
| 158 | static void MemberFn(); |
| 159 | friend void FriendMember::MemberFn(); // expected-warning {{friend declaration naming a member of the declaring class is incompatible with C++98}} |
| 160 | }; |
| 161 | |
| 162 | struct DelegCtor { |
| 163 | DelegCtor(int) : DelegCtor() {} // expected-warning {{delegating constructors are incompatible with C++98}} |
| 164 | DelegCtor(); |
| 165 | }; |
| 166 | |
| 167 | template<int n = 0> void DefaultFuncTemplateArg(); // expected-warning {{default template arguments for a function template are incompatible with C++98}} |
| 168 | |
| 169 | template<typename T> int TemplateFn(T) { return 0; } |
| 170 | void LocalTemplateArg() { |
| 171 | struct S {}; |
| 172 | TemplateFn(S()); // expected-warning {{local type 'S' as template argument is incompatible with C++98}} |
| 173 | } |
| 174 | struct {} obj_of_unnamed_type; // expected-note {{here}} |
| 175 | int UnnamedTemplateArg = TemplateFn(obj_of_unnamed_type); // expected-warning {{unnamed type as template argument is incompatible with C++98}} |
| 176 | |
| 177 | namespace RedundantParensInAddressTemplateParam { |
| 178 | int n; |
| 179 | template<int*p> struct S {}; |
| 180 | S<(&n)> s; // expected-warning {{redundant parentheses surrounding address non-type template argument are incompatible with C++98}} |
| 181 | S<(((&n)))> t; // expected-warning {{redundant parentheses surrounding address non-type template argument are incompatible with C++98}} |
| 182 | } |
| 183 | |
| 184 | namespace TemplateSpecOutOfScopeNs { |
| 185 | template<typename T> struct S {}; // expected-note {{here}} |
| 186 | } |
| 187 | template<> struct TemplateSpecOutOfScopeNs::S<char> {}; // expected-warning {{class template specialization of 'S' outside namespace 'TemplateSpecOutOfScopeNs' is incompatible with C++98}} |
| 188 | |
| 189 | struct Typename { |
| 190 | template<typename T> struct Inner {}; |
| 191 | }; |
| 192 | typename ::Typename TypenameOutsideTemplate(); // expected-warning {{use of 'typename' outside of a template is incompatible with C++98}} |
| 193 | Typename::template Inner<int> TemplateOutsideTemplate(); // expected-warning {{use of 'template' keyword outside of a template is incompatible with C++98}} |
| 194 | |
| 195 | struct TrivialButNonPOD { |
| 196 | int f(int); |
| 197 | private: |
| 198 | int k; |
| 199 | }; |
| 200 | void Ellipsis(int n, ...); |
| 201 | void TrivialButNonPODThroughEllipsis() { |
| 202 | Ellipsis(1, TrivialButNonPOD()); // expected-warning {{passing object of trivial but non-POD type 'TrivialButNonPOD' through variadic function is incompatible with C++98}} |
| 203 | } |
| 204 | |
| 205 | struct HasExplicitConversion { |
| 206 | explicit operator bool(); // expected-warning {{explicit conversion functions are incompatible with C++98}} |
| 207 | }; |
| Richard Smith | c823973 | 2011-10-18 21:39:00 +0000 | [diff] [blame] | 208 | |
| 209 | struct Struct {}; |
| 210 | enum Enum { enum_val = 0 }; |
| 211 | struct BadFriends { |
| 212 | friend enum ::Enum; // expected-warning {{befriending enumeration type 'enum ::Enum' is incompatible with C++98}} |
| 213 | friend int; // expected-warning {{non-class friend type 'int' is incompatible with C++98}} |
| 214 | friend Struct; // expected-warning {{befriending 'Struct' without 'struct' keyword is incompatible with C++98}} |
| 215 | }; |
| 216 | |
| 217 | int n = {}; // expected-warning {{scalar initialized from empty initializer list is incompatible with C++98}} |
| Richard Smith | 38c0e04 | 2011-10-19 00:07:01 +0000 | [diff] [blame] | 218 | |
| 219 | class PrivateMember { |
| 220 | struct ImPrivate {}; |
| 221 | }; |
| Nick Lewycky | 5641233 | 2014-01-11 02:37:12 +0000 | [diff] [blame] | 222 | template<typename T> typename T::ImPrivate SFINAEAccessControl(T t) { // expected-warning {{substitution failure due to access control is incompatible with C++98}} |
| Richard Smith | 38c0e04 | 2011-10-19 00:07:01 +0000 | [diff] [blame] | 223 | return typename T::ImPrivate(); |
| 224 | } |
| 225 | int SFINAEAccessControl(...) { return 0; } |
| Nick Lewycky | 5641233 | 2014-01-11 02:37:12 +0000 | [diff] [blame] | 226 | int CheckSFINAEAccessControl = SFINAEAccessControl(PrivateMember()); // expected-note {{while substituting deduced template arguments into function template 'SFINAEAccessControl' [with T = PrivateMember]}} |
| Richard Smith | a066ccf | 2011-10-19 00:54:10 +0000 | [diff] [blame] | 227 | |
| Richard Smith | f720df0 | 2011-10-19 20:41:51 +0000 | [diff] [blame] | 228 | namespace UnionOrAnonStructMembers { |
| 229 | struct NonTrivCtor { |
| Richard Smith | 92f241f | 2012-12-08 02:53:02 +0000 | [diff] [blame] | 230 | NonTrivCtor(); // expected-note 2{{user-provided default constructor}} |
| Richard Smith | f720df0 | 2011-10-19 20:41:51 +0000 | [diff] [blame] | 231 | }; |
| 232 | struct NonTrivCopy { |
| Richard Smith | 92f241f | 2012-12-08 02:53:02 +0000 | [diff] [blame] | 233 | NonTrivCopy(const NonTrivCopy&); // expected-note 2{{user-provided copy constructor}} |
| Richard Smith | f720df0 | 2011-10-19 20:41:51 +0000 | [diff] [blame] | 234 | }; |
| 235 | struct NonTrivDtor { |
| Richard Smith | 92f241f | 2012-12-08 02:53:02 +0000 | [diff] [blame] | 236 | ~NonTrivDtor(); // expected-note 2{{user-provided destructor}} |
| Richard Smith | f720df0 | 2011-10-19 20:41:51 +0000 | [diff] [blame] | 237 | }; |
| 238 | union BadUnion { |
| 239 | NonTrivCtor ntc; // expected-warning {{union member 'ntc' with a non-trivial constructor is incompatible with C++98}} |
| 240 | NonTrivCopy ntcp; // expected-warning {{union member 'ntcp' with a non-trivial copy constructor is incompatible with C++98}} |
| 241 | NonTrivDtor ntd; // expected-warning {{union member 'ntd' with a non-trivial destructor is incompatible with C++98}} |
| 242 | }; |
| 243 | struct Wrap { |
| 244 | struct { |
| 245 | NonTrivCtor ntc; // expected-warning {{anonymous struct member 'ntc' with a non-trivial constructor is incompatible with C++98}} |
| 246 | NonTrivCopy ntcp; // expected-warning {{anonymous struct member 'ntcp' with a non-trivial copy constructor is incompatible with C++98}} |
| 247 | NonTrivDtor ntd; // expected-warning {{anonymous struct member 'ntd' with a non-trivial destructor is incompatible with C++98}} |
| 248 | }; |
| 249 | }; |
| Richard Smith | 4297375 | 2012-02-16 20:41:22 +0000 | [diff] [blame] | 250 | union WithStaticDataMember { |
| 251 | 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}} |
| 252 | static const int n = 0; // expected-warning {{static data member 'n' in union is incompatible with C++98}} |
| 253 | static int k; // expected-warning {{static data member 'k' in union is incompatible with C++98}} |
| 254 | }; |
| Richard Smith | f720df0 | 2011-10-19 20:41:51 +0000 | [diff] [blame] | 255 | } |
| Richard Smith | 91c7bbd | 2011-10-20 03:28:47 +0000 | [diff] [blame] | 256 | |
| 257 | int EnumNNS = Enum::enum_val; // expected-warning {{enumeration type in nested name specifier is incompatible with C++98}} |
| 258 | template<typename T> void EnumNNSFn() { |
| 259 | int k = T::enum_val; // expected-warning {{enumeration type in nested name specifier is incompatible with C++98}} |
| 260 | }; |
| 261 | template void EnumNNSFn<Enum>(); // expected-note {{in instantiation}} |
| Richard Smith | fe2750d | 2011-10-20 21:42:12 +0000 | [diff] [blame] | 262 | |
| 263 | void JumpDiagnostics(int n) { |
| Richard Smith | 091405d | 2014-09-06 00:24:58 +0000 | [diff] [blame] | 264 | goto DirectJump; // expected-warning {{jump from this goto statement to its label is incompatible with C++98}} |
| Richard Smith | fe2750d | 2011-10-20 21:42:12 +0000 | [diff] [blame] | 265 | TrivialButNonPOD tnp1; // expected-note {{jump bypasses initialization of non-POD variable}} |
| 266 | |
| 267 | DirectJump: |
| 268 | void *Table[] = {&&DirectJump, &&Later}; |
| Richard Smith | 091405d | 2014-09-06 00:24:58 +0000 | [diff] [blame] | 269 | goto *Table[n]; // expected-warning {{jump from this indirect goto statement to one of its possible targets is incompatible with C++98}} |
| Richard Smith | fe2750d | 2011-10-20 21:42:12 +0000 | [diff] [blame] | 270 | |
| 271 | TrivialButNonPOD tnp2; // expected-note {{jump bypasses initialization of non-POD variable}} |
| Richard Smith | 091405d | 2014-09-06 00:24:58 +0000 | [diff] [blame] | 272 | Later: // expected-note {{possible target of indirect goto statement}} |
| Richard Smith | fe2750d | 2011-10-20 21:42:12 +0000 | [diff] [blame] | 273 | switch (n) { |
| 274 | TrivialButNonPOD tnp3; // expected-note {{jump bypasses initialization of non-POD variable}} |
| Richard Smith | 091405d | 2014-09-06 00:24:58 +0000 | [diff] [blame] | 275 | default: // expected-warning {{jump from switch statement to this case label is incompatible with C++98}} |
| Richard Smith | fe2750d | 2011-10-20 21:42:12 +0000 | [diff] [blame] | 276 | return; |
| 277 | } |
| 278 | } |
| Richard Smith | 2a98611 | 2012-02-25 10:20:59 +0000 | [diff] [blame] | 279 | |
| 280 | namespace UnevaluatedMemberAccess { |
| 281 | struct S { |
| 282 | int n; |
| 283 | int f() { return sizeof(S::n); } // ok |
| 284 | }; |
| 285 | int k = sizeof(S::n); // expected-warning {{use of non-static data member 'n' in an unevaluated context is incompatible with C++98}} |
| 286 | 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}} |
| 287 | } |
| Richard Smith | 2a70e65 | 2012-03-09 22:27:51 +0000 | [diff] [blame] | 288 | |
| 289 | namespace LiteralUCNs { |
| 290 | char c1 = '\u001e'; // expected-warning {{universal character name referring to a control character is incompatible with C++98}} |
| 291 | wchar_t c2 = L'\u0041'; // expected-warning {{specifying character 'A' with a universal character name is incompatible with C++98}} |
| 292 | const char *s1 = "foo\u0031"; // expected-warning {{specifying character '1' with a universal character name is incompatible with C++98}} |
| 293 | const wchar_t *s2 = L"bar\u0085"; // expected-warning {{universal character name referring to a control character is incompatible with C++98}} |
| 294 | } |
| Richard Smith | 9380e0e | 2012-04-04 21:11:30 +0000 | [diff] [blame] | 295 | |
| 296 | namespace NonTypeTemplateArgs { |
| 297 | template<typename T, T v> struct S {}; |
| 298 | const int k = 5; // expected-note {{here}} |
| 299 | static void f() {} // expected-note {{here}} |
| 300 | S<const int&, k> s1; // expected-warning {{non-type template argument referring to object 'k' with internal linkage is incompatible with C++98}} |
| 301 | S<void(&)(), f> s2; // expected-warning {{non-type template argument referring to function 'f' with internal linkage is incompatible with C++98}} |
| 302 | } |
| Richard Smith | bc8c5b5 | 2012-04-26 01:51:03 +0000 | [diff] [blame] | 303 | |
| Richard Smith | bc8c5b5 | 2012-04-26 01:51:03 +0000 | [diff] [blame] | 304 | namespace NullPointerTemplateArg { |
| 305 | struct A {}; |
| 306 | template<int*> struct X {}; |
| 307 | template<int A::*> struct Y {}; |
| 308 | X<(int*)0> x; // expected-warning {{use of null pointer as non-type template argument is incompatible with C++98}} |
| 309 | Y<(int A::*)0> y; // expected-warning {{use of null pointer as non-type template argument is incompatible with C++98}} |
| 310 | } |
| Benjamin Kramer | bc7dd9e | 2012-07-30 15:53:26 +0000 | [diff] [blame] | 311 | |
| 312 | namespace PR13480 { |
| 313 | struct basic_iterator { |
| Richard Smith | 92f241f | 2012-12-08 02:53:02 +0000 | [diff] [blame] | 314 | basic_iterator(const basic_iterator &it) {} // expected-note {{because type 'PR13480::basic_iterator' has a user-provided copy constructor}} |
| 315 | basic_iterator(basic_iterator &it) {} |
| Benjamin Kramer | bc7dd9e | 2012-07-30 15:53:26 +0000 | [diff] [blame] | 316 | }; |
| 317 | |
| 318 | union test { |
| 319 | basic_iterator it; // expected-warning {{union member 'it' with a non-trivial copy constructor is incompatible with C++98}} |
| 320 | }; |
| 321 | } |
| Benjamin Kramer | e3895eb | 2012-07-30 16:41:40 +0000 | [diff] [blame] | 322 | |
| 323 | namespace AssignOpUnion { |
| 324 | struct a { |
| Richard Smith | 92f241f | 2012-12-08 02:53:02 +0000 | [diff] [blame] | 325 | void operator=(const a &it) {} // expected-note {{because type 'AssignOpUnion::a' has a user-provided copy assignment operator}} |
| 326 | void operator=(a &it) {} |
| Benjamin Kramer | e3895eb | 2012-07-30 16:41:40 +0000 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | struct b { |
| Richard Smith | 92f241f | 2012-12-08 02:53:02 +0000 | [diff] [blame] | 330 | void operator=(const b &it) {} // expected-note {{because type 'AssignOpUnion::b' has a user-provided copy assignment operator}} |
| Benjamin Kramer | e3895eb | 2012-07-30 16:41:40 +0000 | [diff] [blame] | 331 | }; |
| 332 | |
| 333 | union test1 { |
| 334 | a x; // expected-warning {{union member 'x' with a non-trivial copy assignment operator is incompatible with C++98}} |
| 335 | b y; // expected-warning {{union member 'y' with a non-trivial copy assignment operator is incompatible with C++98}} |
| 336 | }; |
| 337 | } |
| Douglas Gregor | a3d3fe9 | 2012-08-30 21:47:37 +0000 | [diff] [blame] | 338 | |
| 339 | namespace rdar11736429 { |
| Richard Smith | 92f241f | 2012-12-08 02:53:02 +0000 | [diff] [blame] | 340 | struct X { // expected-note {{because type 'rdar11736429::X' has no default constructor}} |
| Douglas Gregor | a3d3fe9 | 2012-08-30 21:47:37 +0000 | [diff] [blame] | 341 | X(const X&) = delete; // expected-warning{{deleted function definitions are incompatible with C++98}} \ |
| Richard Smith | 92f241f | 2012-12-08 02:53:02 +0000 | [diff] [blame] | 342 | // expected-note {{implicit default constructor suppressed by user-declared constructor}} |
| Douglas Gregor | a3d3fe9 | 2012-08-30 21:47:37 +0000 | [diff] [blame] | 343 | }; |
| 344 | |
| 345 | union S { |
| 346 | X x; // expected-warning{{union member 'x' with a non-trivial constructor is incompatible with C++98}} |
| 347 | }; |
| 348 | } |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 349 | |
| 350 | template<typename T> T var = T(10); |
| Aaron Ballman | dd69ef3 | 2014-08-19 15:55:55 +0000 | [diff] [blame] | 351 | #ifdef CXX14COMPAT |
| 352 | // expected-warning@-2 {{variable templates are incompatible with C++ standards before C++14}} |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 353 | #else |
| Aaron Ballman | dd69ef3 | 2014-08-19 15:55:55 +0000 | [diff] [blame] | 354 | // expected-warning@-4 {{variable templates are a C++14 extension}} |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 355 | #endif |
| 356 | |
| Richard Smith | 0d963d6 | 2014-04-17 02:56:49 +0000 | [diff] [blame] | 357 | // No diagnostic for specializations of variable templates; we will have |
| 358 | // diagnosed the primary template. |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 359 | template<typename T> T* var<T*> = new T(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 360 | template<> int var<int> = 10; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 361 | template int var<int>; |
| 362 | float fvar = var<float>; |
| 363 | |
| Richard Smith | 0d963d6 | 2014-04-17 02:56:49 +0000 | [diff] [blame] | 364 | class A { |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 365 | template<typename T> static T var = T(10); |
| Aaron Ballman | dd69ef3 | 2014-08-19 15:55:55 +0000 | [diff] [blame] | 366 | #ifdef CXX14COMPAT |
| 367 | // expected-warning@-2 {{variable templates are incompatible with C++ standards before C++14}} |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 368 | #else |
| Aaron Ballman | dd69ef3 | 2014-08-19 15:55:55 +0000 | [diff] [blame] | 369 | // expected-warning@-4 {{variable templates are a C++14 extension}} |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 370 | #endif |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 371 | |
| Aaron Ballman | dd69ef3 | 2014-08-19 15:55:55 +0000 | [diff] [blame] | 372 | template<typename T> static T* var<T*> = new T(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 373 | }; |
| 374 | |
| 375 | struct B { template<typename T> static T v; }; |
| Aaron Ballman | dd69ef3 | 2014-08-19 15:55:55 +0000 | [diff] [blame] | 376 | #ifdef CXX14COMPAT |
| 377 | // expected-warning@-2 {{variable templates are incompatible with C++ standards before C++14}} |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 378 | #else |
| Aaron Ballman | dd69ef3 | 2014-08-19 15:55:55 +0000 | [diff] [blame] | 379 | // expected-warning@-4 {{variable templates are a C++14 extension}} |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 380 | #endif |
| 381 | |
| 382 | template<typename T> T B::v = T(); |
| Aaron Ballman | dd69ef3 | 2014-08-19 15:55:55 +0000 | [diff] [blame] | 383 | #ifdef CXX14COMPAT |
| 384 | // expected-warning@-2 {{variable templates are incompatible with C++ standards before C++14}} |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 385 | #else |
| Aaron Ballman | dd69ef3 | 2014-08-19 15:55:55 +0000 | [diff] [blame] | 386 | // expected-warning@-4 {{variable templates are a C++14 extension}} |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 387 | #endif |
| 388 | |
| 389 | template<typename T> T* B::v<T*> = new T(); |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 390 | template<> int B::v<int> = 10; |
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 391 | template int B::v<int>; |
| 392 | float fsvar = B::v<float>; |
| 393 | |
| Aaron Ballman | dd69ef3 | 2014-08-19 15:55:55 +0000 | [diff] [blame] | 394 | #ifdef CXX14COMPAT |
| 395 | int digit_seps = 123'456; // expected-warning {{digit separators are incompatible with C++ standards before C++14}} |
| Richard Smith | fde9485 | 2013-09-26 03:33:06 +0000 | [diff] [blame] | 396 | #endif |