1 // RUN: %clang_cc1 -verify -std=c++11 -Wno-anonymous-pack-parens %s 2 // RUN: cp %s %t 3 // RUN: not %clang_cc1 -x c++ -std=c++11 -fixit %t 4 // RUN: %clang_cc1 -Wall -pedantic -x c++ -std=c++11 %t 5 6 /* This is a test of the various code modification hints that only 7 apply in C++0x. */ 8 struct A { 9 explicit operator int(); // expected-note{{conversion to integral type}} 10 }; 11 12 void x() { 13 switch(A()) { // expected-error{{explicit conversion to}} 14 } 15 } 16 17 using ::T = void; // expected-error {{name defined in alias declaration must be an identifier}} 18 using typename U = void; // expected-error {{name defined in alias declaration must be an identifier}} 19 using typename ::V = void; // expected-error {{name defined in alias declaration must be an identifier}} 20 21 namespace SemiCommaTypo { 22 int m {}, 23 n [[]], // expected-error {{expected ';' at end of declaration}} 24 int o; 25 26 struct Base { 27 virtual void f2(), f3(); 28 }; 29 struct MemberDeclarator : Base { 30 int k : 4, 31 //[[]] : 1, FIXME: test this once we support attributes here 32 : 9, // expected-error {{expected ';' at end of declaration}} 33 char c, // expected-error {{expected ';' at end of declaration}} 34 typedef void F(), // expected-error {{expected ';' at end of declaration}} 35 F f1, 36 f2 final, 37 f3 override, // expected-error {{expected ';' at end of declaration}} 38 }; 39 } 40 41 namespace ScopedEnum { 42 enum class E { a }; 43 44 enum class E b = E::a; // expected-error {{must use 'enum' not 'enum class'}} 45 struct S { 46 friend enum class E; // expected-error {{must use 'enum' not 'enum class'}} 47 }; 48 } 49 50 struct S2 { 51 void f(int i); 52 void g(int i); 53 }; 54 55 void S2::f(int i) { 56 (void)[&, &i, &i]{}; // expected-error 2{{'&' cannot precede a capture when the capture default is '&'}} 57 (void)[=, this]{ this->g(5); }; // expected-error{{'this' cannot be explicitly captured}} 58 (void)[i, i]{ }; // expected-error{{'i' can appear only once in a capture list}} 59 (void)[&, i, i]{ }; // expected-error{{'i' can appear only once in a capture list}} 60 (void)[] mutable { }; // expected-error{{lambda requires '()' before 'mutable'}} 61 (void)[] -> int { }; // expected-error{{lambda requires '()' before return type}} 62 } 63 64 #define bar "bar" 65 const char *p = "foo"bar; // expected-error {{requires a space between}} 66 #define ord - '0' 67 int k = '4'ord; // expected-error {{requires a space between}} 68 69 void operator"x" _y(char); // expected-error {{must be '""'}} 70 void operator L"" _z(char); // expected-error {{encoding prefix}} 71 void operator "x" "y" U"z" ""_whoops "z" "y"(char); // expected-error {{must be '""'}} 72 73 void f() { 74 'b'_y; 75 'c'_z; 76 'd'_whoops; 77 } 78 79 template<typename ...Ts> struct MisplacedEllipsis { 80 int a(Ts ...(x)); // expected-error {{'...' must immediately precede declared identifier}} 81 int b(Ts ...&x); // expected-error {{'...' must immediately precede declared identifier}} 82 int c(Ts ...&); // expected-error {{'...' must be innermost component of anonymous pack declaration}} 83 int d(Ts ...(...&...)); // expected-error 2{{'...' must be innermost component of anonymous pack declaration}} 84 int e(Ts ...*[]); // expected-error {{'...' must be innermost component of anonymous pack declaration}} 85 int f(Ts ...(...*)()); // expected-error 2{{'...' must be innermost component of anonymous pack declaration}} 86 int g(Ts ...()); // ok 87 }; 88 namespace TestMisplacedEllipsisRecovery { 89 MisplacedEllipsis<int, char> me; 90 int i; char k; 91 int *ip; char *kp; 92 int ifn(); char kfn(); 93 int a = me.a(i, k); 94 int b = me.b(i, k); 95 int c = me.c(i, k); 96 int d = me.d(i, k); 97 int e = me.e(&ip, &kp); 98 int f = me.f(ifn, kfn); 99 int g = me.g(ifn, kfn); 100 } 101 102 template<template<typename> ...Foo, // expected-error {{template template parameter requires 'class' after the parameter list}} 103 template<template<template<typename>>>> // expected-error 3 {{template template parameter requires 'class' after the parameter list}} 104 void func(); 105 106 template<int *ip> struct IP { }; // expected-note{{declared here}} 107 IP<0> ip0; // expected-error{{null non-type template argument must be cast to template parameter type 'int *'}} 108 109 namespace MissingSemi { 110 struct a // expected-error {{expected ';' after struct}} 111 struct b // expected-error {{expected ';' after struct}} 112 enum x : int { x1, x2, x3 } // expected-error {{expected ';' after enum}} 113 struct c // expected-error {{expected ';' after struct}} 114 enum x : int // expected-error {{expected ';' after enum}} 115 // FIXME: The following gives a poor diagnostic (we parse the 'int' and the 116 // 'struct' as part of the same enum-base. 117 // enum x : int 118 // struct y 119 namespace N { 120 struct d // expected-error {{expected ';' after struct}} 121 } 122 } 123 124 namespace NonStaticConstexpr { 125 struct foo { 126 constexpr int i; // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}} 127 constexpr int j = 7; // expected-error {{non-static data member cannot be constexpr; did you intend to make it static?}} 128 constexpr const int k; // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}} 129 foo() : i(3), k(4) { 130 } 131 static int get_j() { 132 return j; 133 } 134 }; 135 } 136 137 int RegisterVariable() { 138 register int n; // expected-warning {{'register' storage class specifier is deprecated}} 139 return n; 140 } 141 142 namespace MisplacedParameterPack { 143 template <typename Args...> // expected-error {{'...' must immediately precede declared identifier}} 144 void misplacedEllipsisInTypeParameter(Args...); 145 146 template <typename... Args...> // expected-error {{'...' must immediately precede declared identifier}} 147 void redundantEllipsisInTypeParameter(Args...); 148 149 template <template <typename> class Args...> // expected-error {{'...' must immediately precede declared identifier}} 150 void misplacedEllipsisInTemplateTypeParameter(Args<int>...); 151 152 template <template <typename> class... Args...> // expected-error {{'...' must immediately precede declared identifier}} 153 void redundantEllipsisInTemplateTypeParameter(Args<int>...); 154 155 template <int N...> // expected-error {{'...' must immediately precede declared identifier}} 156 void misplacedEllipsisInNonTypeTemplateParameter(); 157 158 template <int... N...> // expected-error {{'...' must immediately precede declared identifier}} 159 void redundantEllipsisInNonTypeTemplateParameter(); 160 } 161 162 namespace MisplacedDeclAndRefSpecAfterVirtSpec { 163 struct B { 164 virtual void f(); 165 virtual void f() volatile const; 166 }; 167 struct D : B { 168 virtual void f() override; 169 virtual void f() override final const volatile; // expected-error {{'const' qualifier may not appear after the virtual specifier 'final'}} expected-error {{'volatile' qualifier may not appear after the virtual specifier 'final'}} 170 }; 171 struct B2 { 172 virtual void f() &; 173 virtual void f() volatile const &&; 174 }; 175 struct D2 : B2 { 176 virtual void f() override &; // expected-error {{'&' qualifier may not appear after the virtual specifier 'override'}} 177 virtual void f() override final const volatile &&; // expected-error {{'const' qualifier may not appear after the virtual specifier 'final'}} expected-error {{'volatile' qualifier may not appear after the virtual specifier 'final'}} expected-error {{'&&' qualifier may not appear after the virtual specifier 'final'}} 178 }; 179 } 180