blob: a173ce4bc271581607340100b29a456e0d5a8611 [file] [log] [blame]
Richard Smith762bb9d2011-10-13 22:29:44 +00001// RUN: %clang_cc1 -verify -std=c++11 %s
Nick Lewyckyba5f6ec2010-04-24 01:30:46 +00002// RUN: cp %s %t
Richard Smith762bb9d2011-10-13 22:29:44 +00003// RUN: not %clang_cc1 -x c++ -std=c++11 -fixit %t
4// RUN: %clang_cc1 -Wall -pedantic -x c++ -std=c++11 %t
Douglas Gregor84fb9c02009-11-23 13:46:08 +00005
6/* This is a test of the various code modification hints that only
7 apply in C++0x. */
Nick Lewyckyba5f6ec2010-04-24 01:30:46 +00008struct A {
Douglas Gregor84fb9c02009-11-23 13:46:08 +00009 explicit operator int(); // expected-note{{conversion to integral type}}
10};
11
Nick Lewyckyba5f6ec2010-04-24 01:30:46 +000012void x() {
Douglas Gregor84fb9c02009-11-23 13:46:08 +000013 switch(A()) { // expected-error{{explicit conversion to}}
14 }
15}
16
Richard Smith162e1c12011-04-15 14:24:37 +000017using ::T = void; // expected-error {{name defined in alias declaration must be an identifier}}
18using typename U = void; // expected-error {{name defined in alias declaration must be an identifier}}
19using typename ::V = void; // expected-error {{name defined in alias declaration must be an identifier}}
Richard Smithc6d990a2011-09-29 19:11:37 +000020
Richard Smith0706df42011-10-19 21:33:05 +000021namespace SemiCommaTypo {
22 int m {},
23 n [[]], // expected-error {{expected ';' at end of declaration}}
24 int o;
Richard Smith1c94c162012-01-09 22:31:44 +000025
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 };
Richard Smith0706df42011-10-19 21:33:05 +000039}
Richard Smithbdad7a22012-01-10 01:33:14 +000040
41namespace 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}
Douglas Gregor3ac109c2012-02-10 17:46:20 +000049
50struct S2 {
51 void f(int i);
52 void g(int i);
53};
54
55void 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}}
Richard Smith92dc0352012-02-17 01:39:04 +000060 (void)[] mutable { }; // expected-error{{lambda requires '()' before 'mutable'}}
61 (void)[] -> int { }; // expected-error{{lambda requires '()' before return type}}
Douglas Gregor3ac109c2012-02-10 17:46:20 +000062}
Richard Smith2fb4ae32012-03-08 02:39:21 +000063
64#define bar "bar"
65const char *p = "foo"bar; // expected-error {{requires a space between}}
66#define ord - '0'
67int k = '4'ord; // expected-error {{requires a space between}}
Richard Smith33762772012-03-08 23:06:02 +000068
Richard Smith33762772012-03-08 23:06:02 +000069void operator"x" _y(char); // expected-error {{must be '""'}}
70void operator L"" _z(char); // expected-error {{encoding prefix}}
71void operator "x" "y" U"z" ""_whoops "z" "y"(char); // expected-error {{must be '""'}}
72
73void f() {
Richard Smith33762772012-03-08 23:06:02 +000074 'b'_y;
75 'c'_z;
76 'd'_whoops;
77}
Richard Smith9988f282012-03-29 01:16:42 +000078
79template<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};
88namespace 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}
David Blaikie9df1b962012-04-06 05:26:43 +0000101
David Blaikie673720d2012-04-06 06:28:32 +0000102template<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}}
David Blaikie9df1b962012-04-06 05:26:43 +0000104void func();
Douglas Gregord2008e22012-04-06 22:40:38 +0000105
106template<int *ip> struct IP { }; // expected-note{{declared here}}
107IP<0> ip0; // expected-error{{null non-type template argument must be cast to template parameter type 'int *'}}
108
Richard Smithc9f35172012-06-25 21:37:02 +0000109namespace 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}