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