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