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