Richard Smith | b19337f | 2013-02-20 20:19:27 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -std=c++11 -Wno-anonymous-pack-parens %s |
Nick Lewycky | 784fad7 | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 2 | // RUN: cp %s %t |
Richard Smith | 9ca5c42 | 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 | d0c22e0 | 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 | 784fad7 | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 8 | struct A { |
Douglas Gregor | d0c22e0 | 2009-11-23 13:46:08 +0000 | [diff] [blame] | 9 | explicit operator int(); // expected-note{{conversion to integral type}} |
| 10 | }; |
| 11 | |
Nick Lewycky | 784fad7 | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 12 | void x() { |
Douglas Gregor | d0c22e0 | 2009-11-23 13:46:08 +0000 | [diff] [blame] | 13 | switch(A()) { // expected-error{{explicit conversion to}} |
| 14 | } |
| 15 | } |
| 16 | |
Richard Smith | dda56e4 | 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 | 2316cd8 | 2011-09-29 19:11:37 +0000 | [diff] [blame] | 20 | |
Richard Smith | 09f76ee | 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 | c8a7903 | 2012-01-09 22:31:44 +0000 | [diff] [blame] | 25 | |
| 26 | struct Base { |
Alexander Potapenko | e2e8b0e | 2014-10-03 09:02:53 +0000 | [diff] [blame] | 27 | virtual void f2(), f3(); |
Richard Smith | c8a7903 | 2012-01-09 22:31:44 +0000 | [diff] [blame] | 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, |
Alexander Potapenko | e2e8b0e | 2014-10-03 09:02:53 +0000 | [diff] [blame] | 36 | f2 final, |
Richard Smith | c8a7903 | 2012-01-09 22:31:44 +0000 | [diff] [blame] | 37 | f3 override, // expected-error {{expected ';' at end of declaration}} |
| 38 | }; |
Richard Smith | 09f76ee | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 39 | } |
Richard Smith | 0f8ee22 | 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 | a1bffa2 | 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 '&'}} |
Douglas Gregor | a1bffa2 | 2012-02-10 17:46:20 +0000 | [diff] [blame] | 57 | (void)[i, i]{ }; // expected-error{{'i' can appear only once in a capture list}} |
| 58 | (void)[&, i, i]{ }; // expected-error{{'i' can appear only once in a capture list}} |
Richard Smith | 50965d9 | 2012-02-17 01:39:04 +0000 | [diff] [blame] | 59 | (void)[] mutable { }; // expected-error{{lambda requires '()' before 'mutable'}} |
| 60 | (void)[] -> int { }; // expected-error{{lambda requires '()' before return type}} |
Douglas Gregor | a1bffa2 | 2012-02-10 17:46:20 +0000 | [diff] [blame] | 61 | } |
Richard Smith | 0df56f4 | 2012-03-08 02:39:21 +0000 | [diff] [blame] | 62 | |
| 63 | #define bar "bar" |
| 64 | const char *p = "foo"bar; // expected-error {{requires a space between}} |
| 65 | #define ord - '0' |
| 66 | int k = '4'ord; // expected-error {{requires a space between}} |
Richard Smith | 7d182a7 | 2012-03-08 23:06:02 +0000 | [diff] [blame] | 67 | |
Richard Smith | 7d182a7 | 2012-03-08 23:06:02 +0000 | [diff] [blame] | 68 | void operator"x" _y(char); // expected-error {{must be '""'}} |
| 69 | void operator L"" _z(char); // expected-error {{encoding prefix}} |
| 70 | void operator "x" "y" U"z" ""_whoops "z" "y"(char); // expected-error {{must be '""'}} |
| 71 | |
| 72 | void f() { |
Richard Smith | 7d182a7 | 2012-03-08 23:06:02 +0000 | [diff] [blame] | 73 | 'b'_y; |
| 74 | 'c'_z; |
| 75 | 'd'_whoops; |
| 76 | } |
Richard Smith | 0efa75c | 2012-03-29 01:16:42 +0000 | [diff] [blame] | 77 | |
| 78 | template<typename ...Ts> struct MisplacedEllipsis { |
| 79 | int a(Ts ...(x)); // expected-error {{'...' must immediately precede declared identifier}} |
| 80 | int b(Ts ...&x); // expected-error {{'...' must immediately precede declared identifier}} |
| 81 | int c(Ts ...&); // expected-error {{'...' must be innermost component of anonymous pack declaration}} |
| 82 | int d(Ts ...(...&...)); // expected-error 2{{'...' must be innermost component of anonymous pack declaration}} |
| 83 | int e(Ts ...*[]); // expected-error {{'...' must be innermost component of anonymous pack declaration}} |
| 84 | int f(Ts ...(...*)()); // expected-error 2{{'...' must be innermost component of anonymous pack declaration}} |
| 85 | int g(Ts ...()); // ok |
| 86 | }; |
| 87 | namespace TestMisplacedEllipsisRecovery { |
| 88 | MisplacedEllipsis<int, char> me; |
| 89 | int i; char k; |
| 90 | int *ip; char *kp; |
| 91 | int ifn(); char kfn(); |
| 92 | int a = me.a(i, k); |
| 93 | int b = me.b(i, k); |
| 94 | int c = me.c(i, k); |
| 95 | int d = me.d(i, k); |
| 96 | int e = me.e(&ip, &kp); |
| 97 | int f = me.f(ifn, kfn); |
| 98 | int g = me.g(ifn, kfn); |
| 99 | } |
David Blaikie | cbd8125 | 2012-04-06 05:26:43 +0000 | [diff] [blame] | 100 | |
David Blaikie | 3697983 | 2012-04-06 06:28:32 +0000 | [diff] [blame] | 101 | template<template<typename> ...Foo, // expected-error {{template template parameter requires 'class' after the parameter list}} |
| 102 | template<template<template<typename>>>> // expected-error 3 {{template template parameter requires 'class' after the parameter list}} |
David Blaikie | cbd8125 | 2012-04-06 05:26:43 +0000 | [diff] [blame] | 103 | void func(); |
Douglas Gregor | 31f55dc | 2012-04-06 22:40:38 +0000 | [diff] [blame] | 104 | |
| 105 | template<int *ip> struct IP { }; // expected-note{{declared here}} |
| 106 | IP<0> ip0; // expected-error{{null non-type template argument must be cast to template parameter type 'int *'}} |
| 107 | |
Richard Smith | 369b9f9 | 2012-06-25 21:37:02 +0000 | [diff] [blame] | 108 | namespace MissingSemi { |
| 109 | struct a // expected-error {{expected ';' after struct}} |
| 110 | struct b // expected-error {{expected ';' after struct}} |
| 111 | enum x : int { x1, x2, x3 } // expected-error {{expected ';' after enum}} |
| 112 | struct c // expected-error {{expected ';' after struct}} |
| 113 | enum x : int // expected-error {{expected ';' after enum}} |
| 114 | // FIXME: The following gives a poor diagnostic (we parse the 'int' and the |
| 115 | // 'struct' as part of the same enum-base. |
| 116 | // enum x : int |
| 117 | // struct y |
| 118 | namespace N { |
| 119 | struct d // expected-error {{expected ';' after struct}} |
| 120 | } |
| 121 | } |
David Blaikie | 35506f8 | 2013-01-30 01:22:18 +0000 | [diff] [blame] | 122 | |
| 123 | namespace NonStaticConstexpr { |
| 124 | struct foo { |
| 125 | constexpr int i; // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}} |
| 126 | constexpr int j = 7; // expected-error {{non-static data member cannot be constexpr; did you intend to make it static?}} |
Richard Smith | 82dce55 | 2014-04-14 21:00:40 +0000 | [diff] [blame] | 127 | constexpr const int k; // expected-error {{non-static data member cannot be constexpr; did you intend to make it const?}} |
| 128 | foo() : i(3), k(4) { |
David Blaikie | 35506f8 | 2013-01-30 01:22:18 +0000 | [diff] [blame] | 129 | } |
| 130 | static int get_j() { |
| 131 | return j; |
| 132 | } |
| 133 | }; |
| 134 | } |
Richard Smith | 8ca78a1 | 2013-06-13 02:02:51 +0000 | [diff] [blame] | 135 | |
| 136 | int RegisterVariable() { |
| 137 | register int n; // expected-warning {{'register' storage class specifier is deprecated}} |
| 138 | return n; |
| 139 | } |
Nikola Smiljanic | 69fdc9f | 2014-06-06 02:58:59 +0000 | [diff] [blame] | 140 | |
| 141 | namespace MisplacedParameterPack { |
| 142 | template <typename Args...> // expected-error {{'...' must immediately precede declared identifier}} |
| 143 | void misplacedEllipsisInTypeParameter(Args...); |
| 144 | |
| 145 | template <typename... Args...> // expected-error {{'...' must immediately precede declared identifier}} |
| 146 | void redundantEllipsisInTypeParameter(Args...); |
| 147 | |
| 148 | template <template <typename> class Args...> // expected-error {{'...' must immediately precede declared identifier}} |
| 149 | void misplacedEllipsisInTemplateTypeParameter(Args<int>...); |
| 150 | |
| 151 | template <template <typename> class... Args...> // expected-error {{'...' must immediately precede declared identifier}} |
| 152 | void redundantEllipsisInTemplateTypeParameter(Args<int>...); |
| 153 | |
| 154 | template <int N...> // expected-error {{'...' must immediately precede declared identifier}} |
| 155 | void misplacedEllipsisInNonTypeTemplateParameter(); |
| 156 | |
| 157 | template <int... N...> // expected-error {{'...' must immediately precede declared identifier}} |
| 158 | void redundantEllipsisInNonTypeTemplateParameter(); |
| 159 | } |
Ehsan Akhgari | 93ed5cf | 2015-03-25 00:53:27 +0000 | [diff] [blame] | 160 | |
Ehsan Akhgari | c07d1e2 | 2015-03-25 00:53:33 +0000 | [diff] [blame] | 161 | namespace MisplacedDeclAndRefSpecAfterVirtSpec { |
Ehsan Akhgari | 93ed5cf | 2015-03-25 00:53:27 +0000 | [diff] [blame] | 162 | struct B { |
| 163 | virtual void f(); |
| 164 | virtual void f() volatile const; |
| 165 | }; |
| 166 | struct D : B { |
| 167 | virtual void f() override; |
| 168 | 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'}} |
| 169 | }; |
Ehsan Akhgari | c07d1e2 | 2015-03-25 00:53:33 +0000 | [diff] [blame] | 170 | struct B2 { |
| 171 | virtual void f() &; |
| 172 | virtual void f() volatile const &&; |
| 173 | }; |
| 174 | struct D2 : B2 { |
| 175 | virtual void f() override &; // expected-error {{'&' qualifier may not appear after the virtual specifier 'override'}} |
| 176 | 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'}} |
| 177 | }; |
Ehsan Akhgari | 93ed5cf | 2015-03-25 00:53:27 +0000 | [diff] [blame] | 178 | } |