Richard Smith | 762bb9d | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -std=c++11 %s |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 2 | // RUN: cp %s %t |
Richard Smith | 762bb9d | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 3 | // RUN: not %clang_cc1 -x c++ -std=c++11 -fixit %t |
| 4 | // RUN: %clang_cc1 -Wall -pedantic -x c++ -std=c++11 %t |
Douglas Gregor | 84fb9c0 | 2009-11-23 13:46:08 +0000 | [diff] [blame] | 5 | |
| 6 | /* This is a test of the various code modification hints that only |
| 7 | apply in C++0x. */ |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 8 | struct A { |
Douglas Gregor | 84fb9c0 | 2009-11-23 13:46:08 +0000 | [diff] [blame] | 9 | explicit operator int(); // expected-note{{conversion to integral type}} |
| 10 | }; |
| 11 | |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 12 | void x() { |
Douglas Gregor | 84fb9c0 | 2009-11-23 13:46:08 +0000 | [diff] [blame] | 13 | switch(A()) { // expected-error{{explicit conversion to}} |
| 14 | } |
| 15 | } |
| 16 | |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 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}} |
Richard Smith | c6d990a | 2011-09-29 19:11:37 +0000 | [diff] [blame] | 20 | |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 21 | namespace SemiCommaTypo { |
| 22 | int m {}, |
| 23 | n [[]], // expected-error {{expected ';' at end of declaration}} |
| 24 | int o; |
Richard Smith | 1c94c16 | 2012-01-09 22:31:44 +0000 | [diff] [blame] | 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 | }; |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 39 | } |
Richard Smith | bdad7a2 | 2012-01-10 01:33:14 +0000 | [diff] [blame] | 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 | } |
Douglas Gregor | 3ac109c | 2012-02-10 17:46:20 +0000 | [diff] [blame] | 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}} |
Richard Smith | 92dc035 | 2012-02-17 01:39:04 +0000 | [diff] [blame] | 60 | (void)[] mutable { }; // expected-error{{lambda requires '()' before 'mutable'}} |
| 61 | (void)[] -> int { }; // expected-error{{lambda requires '()' before return type}} |
Douglas Gregor | 3ac109c | 2012-02-10 17:46:20 +0000 | [diff] [blame] | 62 | } |
Richard Smith | 2fb4ae3 | 2012-03-08 02:39:21 +0000 | [diff] [blame] | 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}} |
Richard Smith | 3376277 | 2012-03-08 23:06:02 +0000 | [diff] [blame] | 68 | |
| 69 | void operator""_x(char); // expected-error {{requires a space}} |
| 70 | void operator"x" _y(char); // expected-error {{must be '""'}} |
| 71 | void operator L"" _z(char); // expected-error {{encoding prefix}} |
| 72 | void operator "x" "y" U"z" ""_whoops "z" "y"(char); // expected-error {{must be '""'}} |
| 73 | |
| 74 | void f() { |
| 75 | 'a'_x; |
| 76 | 'b'_y; |
| 77 | 'c'_z; |
| 78 | 'd'_whoops; |
| 79 | } |
Richard Smith | 9988f28 | 2012-03-29 01:16:42 +0000 | [diff] [blame] | 80 | |
| 81 | template<typename ...Ts> struct MisplacedEllipsis { |
| 82 | int a(Ts ...(x)); // expected-error {{'...' must immediately precede declared identifier}} |
| 83 | int b(Ts ...&x); // expected-error {{'...' must immediately precede declared identifier}} |
| 84 | int c(Ts ...&); // expected-error {{'...' must be innermost component of anonymous pack declaration}} |
| 85 | int d(Ts ...(...&...)); // expected-error 2{{'...' must be innermost component of anonymous pack declaration}} |
| 86 | int e(Ts ...*[]); // expected-error {{'...' must be innermost component of anonymous pack declaration}} |
| 87 | int f(Ts ...(...*)()); // expected-error 2{{'...' must be innermost component of anonymous pack declaration}} |
| 88 | int g(Ts ...()); // ok |
| 89 | }; |
| 90 | namespace TestMisplacedEllipsisRecovery { |
| 91 | MisplacedEllipsis<int, char> me; |
| 92 | int i; char k; |
| 93 | int *ip; char *kp; |
| 94 | int ifn(); char kfn(); |
| 95 | int a = me.a(i, k); |
| 96 | int b = me.b(i, k); |
| 97 | int c = me.c(i, k); |
| 98 | int d = me.d(i, k); |
| 99 | int e = me.e(&ip, &kp); |
| 100 | int f = me.f(ifn, kfn); |
| 101 | int g = me.g(ifn, kfn); |
| 102 | } |
David Blaikie | 9df1b96 | 2012-04-06 05:26:43 +0000 | [diff] [blame^] | 103 | |
| 104 | template<template<typename> ...Foo, // expected-error {{template template parameters require 'class' after the parameter list}} |
| 105 | template<template<template<typename>>>> // expected-error 3 {{template template parameters require 'class' after the parameter list}} |
| 106 | void func(); |