Richard Smith | 6e1fd33 | 2011-11-29 09:09:06 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -pedantic -Wall -Wno-comment -verify -fcxx-exceptions -x c++ %s |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 2 | // RUN: cp %s %t |
Richard Smith | 6e1fd33 | 2011-11-29 09:09:06 +0000 | [diff] [blame] | 3 | // RUN: not %clang_cc1 -pedantic -Wall -Wno-comment -fcxx-exceptions -fixit -x c++ %t |
| 4 | // RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror -Wno-comment -fcxx-exceptions -x c++ %t |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 5 | |
| 6 | /* This is a test of the various code modification hints that are |
Douglas Gregor | fe057ac | 2009-04-02 03:20:30 +0000 | [diff] [blame] | 7 | provided as part of warning or extension diagnostics. All of the |
| 8 | warnings will be fixed by -fixit, and the resulting file should |
| 9 | compile cleanly with -Werror -pedantic. */ |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 10 | |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 11 | struct C1 { |
Douglas Gregor | a3a8351 | 2009-04-01 23:51:29 +0000 | [diff] [blame] | 12 | virtual void f(); |
| 13 | static void g(); |
| 14 | }; |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 15 | struct C2 : virtual public virtual C1 { }; // expected-error{{duplicate}} |
| 16 | |
Douglas Gregor | a3a8351 | 2009-04-01 23:51:29 +0000 | [diff] [blame] | 17 | virtual void C1::f() { } // expected-error{{'virtual' can only be specified inside the class definition}} |
| 18 | |
| 19 | static void C1::g() { } // expected-error{{'static' can only be specified inside the class definition}} |
| 20 | |
| 21 | template<int Value> struct CT { }; // expected-note{{previous use is here}} |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 22 | |
| 23 | CT<10 >> 2> ct; // expected-warning{{require parentheses}} |
Douglas Gregor | a3a8351 | 2009-04-01 23:51:29 +0000 | [diff] [blame] | 24 | |
| 25 | class C3 { |
| 26 | public: |
| 27 | C3(C3, int i = 0); // expected-error{{copy constructor must pass its first argument by reference}} |
| 28 | }; |
| 29 | |
| 30 | struct CT<0> { }; // expected-error{{'template<>'}} |
| 31 | |
Richard Smith | 98e13ea | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 32 | template<> union CT<1> { }; // expected-error{{tag type}} |
Anders Carlsson | ad26b73 | 2009-11-10 03:24:44 +0000 | [diff] [blame] | 33 | |
Douglas Gregor | 2848523 | 2010-02-01 23:46:27 +0000 | [diff] [blame] | 34 | // Access declarations |
| 35 | class A { |
| 36 | protected: |
| 37 | int foo(); |
| 38 | }; |
Anders Carlsson | ad26b73 | 2009-11-10 03:24:44 +0000 | [diff] [blame] | 39 | |
Douglas Gregor | 2848523 | 2010-02-01 23:46:27 +0000 | [diff] [blame] | 40 | class B : public A { |
| 41 | A::foo; // expected-warning{{access declarations are deprecated}} |
| 42 | }; |
Douglas Gregor | 2eef829 | 2010-03-24 07:14:45 +0000 | [diff] [blame] | 43 | |
Richard Smith | 98e13ea | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 44 | void f() throw(); // expected-note{{previous}} |
Douglas Gregor | 2eef829 | 2010-03-24 07:14:45 +0000 | [diff] [blame] | 45 | void f(); // expected-warning{{missing exception specification}} |
Douglas Gregor | 1aae80b | 2010-04-14 20:27:54 +0000 | [diff] [blame] | 46 | |
| 47 | namespace rdar7853795 { |
| 48 | struct A { |
| 49 | bool getNumComponents() const; // expected-note{{declared here}} |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 50 | void dump() const { |
Douglas Gregor | 1aae80b | 2010-04-14 20:27:54 +0000 | [diff] [blame] | 51 | getNumComponenets(); // expected-error{{use of undeclared identifier 'getNumComponenets'; did you mean 'getNumComponents'?}} |
| 52 | } |
| 53 | }; |
| 54 | } |
Douglas Gregor | b1f6fa4 | 2010-09-07 14:35:10 +0000 | [diff] [blame] | 55 | |
| 56 | namespace rdar7796492 { |
| 57 | class A { int x, y; A(); }; |
| 58 | |
| 59 | A::A() |
| 60 | : x(1) y(2) { // expected-error{{missing ',' between base or member initializers}} |
| 61 | } |
| 62 | |
| 63 | } |
Gabor Greif | a4a301d | 2010-09-08 00:31:13 +0000 | [diff] [blame] | 64 | |
Francois Pichet | c71d8eb | 2010-10-01 21:19:28 +0000 | [diff] [blame] | 65 | // extra qualification on member |
| 66 | class C { |
Richard Smith | 98e13ea | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 67 | int C::foo(); // expected-warning {{extra qualification}} |
Francois Pichet | c71d8eb | 2010-10-01 21:19:28 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
Argyrios Kyrtzidis | a6eb5f8 | 2010-10-08 02:39:23 +0000 | [diff] [blame] | 70 | namespace rdar8488464 { |
Richard Trieu | fcaf27e | 2012-01-19 22:01:51 +0000 | [diff] [blame] | 71 | int x = 0; |
| 72 | int x1 &= 0; // expected-error {{invalid '&=' at end of declaration; did you mean '='?}} |
| 73 | int x2 *= 0; // expected-error {{invalid '*=' at end of declaration; did you mean '='?}} |
| 74 | int x3 += 0; // expected-error {{invalid '+=' at end of declaration; did you mean '='?}} |
| 75 | int x4 -= 0; // expected-error {{invalid '-=' at end of declaration; did you mean '='?}} |
| 76 | int x5 != 0; // expected-error {{invalid '!=' at end of declaration; did you mean '='?}} |
| 77 | int x6 /= 0; // expected-error {{invalid '/=' at end of declaration; did you mean '='?}} |
| 78 | int x7 %= 0; // expected-error {{invalid '%=' at end of declaration; did you mean '='?}} |
| 79 | int x8 <= 0; // expected-error {{invalid '<=' at end of declaration; did you mean '='?}} |
| 80 | int x9 <<= 0; // expected-error {{invalid '<<=' at end of declaration; did you mean '='?}} |
| 81 | int x10 >= 0; // expected-error {{invalid '>=' at end of declaration; did you mean '='?}} |
| 82 | int x11 >>= 0; // expected-error {{invalid '>>=' at end of declaration; did you mean '='?}} |
| 83 | int x12 ^= 0; // expected-error {{invalid '^=' at end of declaration; did you mean '='?}} |
| 84 | int x13 |= 0; // expected-error {{invalid '|=' at end of declaration; did you mean '='?}} |
| 85 | int x14 == 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}} |
Argyrios Kyrtzidis | a6eb5f8 | 2010-10-08 02:39:23 +0000 | [diff] [blame] | 86 | |
| 87 | void f() { |
Richard Trieu | fcaf27e | 2012-01-19 22:01:51 +0000 | [diff] [blame] | 88 | int x = 0; |
Argyrios Kyrtzidis | a6eb5f8 | 2010-10-08 02:39:23 +0000 | [diff] [blame] | 89 | (void)x; |
Richard Trieu | fcaf27e | 2012-01-19 22:01:51 +0000 | [diff] [blame] | 90 | int x1 &= 0; // expected-error {{invalid '&=' at end of declaration; did you mean '='?}} |
| 91 | (void)x1; |
| 92 | int x2 *= 0; // expected-error {{invalid '*=' at end of declaration; did you mean '='?}} |
| 93 | (void)x2; |
| 94 | int x3 += 0; // expected-error {{invalid '+=' at end of declaration; did you mean '='?}} |
| 95 | (void)x3; |
| 96 | int x4 -= 0; // expected-error {{invalid '-=' at end of declaration; did you mean '='?}} |
| 97 | (void)x4; |
| 98 | int x5 != 0; // expected-error {{invalid '!=' at end of declaration; did you mean '='?}} |
| 99 | (void)x5; |
| 100 | int x6 /= 0; // expected-error {{invalid '/=' at end of declaration; did you mean '='?}} |
| 101 | (void)x6; |
| 102 | int x7 %= 0; // expected-error {{invalid '%=' at end of declaration; did you mean '='?}} |
| 103 | (void)x7; |
| 104 | int x8 <= 0; // expected-error {{invalid '<=' at end of declaration; did you mean '='?}} |
| 105 | (void)x8; |
| 106 | int x9 <<= 0; // expected-error {{invalid '<<=' at end of declaration; did you mean '='?}} |
| 107 | (void)x9; |
| 108 | int x10 >= 0; // expected-error {{invalid '>=' at end of declaration; did you mean '='?}} |
| 109 | (void)x10; |
| 110 | int x11 >>= 0; // expected-error {{invalid '>>=' at end of declaration; did you mean '='?}} |
| 111 | (void)x11; |
| 112 | int x12 ^= 0; // expected-error {{invalid '^=' at end of declaration; did you mean '='?}} |
| 113 | (void)x12; |
| 114 | int x13 |= 0; // expected-error {{invalid '|=' at end of declaration; did you mean '='?}} |
| 115 | (void)x13; |
| 116 | int x14 == 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}} |
| 117 | (void)x14; |
| 118 | if (int x = 0) { (void)x; } |
| 119 | if (int x1 &= 0) { (void)x1; } // expected-error {{invalid '&=' at end of declaration; did you mean '='?}} |
| 120 | if (int x2 *= 0) { (void)x2; } // expected-error {{invalid '*=' at end of declaration; did you mean '='?}} |
| 121 | if (int x3 += 0) { (void)x3; } // expected-error {{invalid '+=' at end of declaration; did you mean '='?}} |
| 122 | if (int x4 -= 0) { (void)x4; } // expected-error {{invalid '-=' at end of declaration; did you mean '='?}} |
| 123 | if (int x5 != 0) { (void)x5; } // expected-error {{invalid '!=' at end of declaration; did you mean '='?}} |
| 124 | if (int x6 /= 0) { (void)x6; } // expected-error {{invalid '/=' at end of declaration; did you mean '='?}} |
| 125 | if (int x7 %= 0) { (void)x7; } // expected-error {{invalid '%=' at end of declaration; did you mean '='?}} |
| 126 | if (int x8 <= 0) { (void)x8; } // expected-error {{invalid '<=' at end of declaration; did you mean '='?}} |
| 127 | if (int x9 <<= 0) { (void)x9; } // expected-error {{invalid '<<=' at end of declaration; did you mean '='?}} |
| 128 | if (int x10 >= 0) { (void)x10; } // expected-error {{invalid '>=' at end of declaration; did you mean '='?}} |
| 129 | if (int x11 >>= 0) { (void)x11; } // expected-error {{invalid '>>=' at end of declaration; did you mean '='?}} |
| 130 | if (int x12 ^= 0) { (void)x12; } // expected-error {{invalid '^=' at end of declaration; did you mean '='?}} |
| 131 | if (int x13 |= 0) { (void)x13; } // expected-error {{invalid '|=' at end of declaration; did you mean '='?}} |
| 132 | if (int x14 == 0) { (void)x14; } // expected-error {{invalid '==' at end of declaration; did you mean '='?}} |
Argyrios Kyrtzidis | a6eb5f8 | 2010-10-08 02:39:23 +0000 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |
Francois Pichet | 4147d30 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 136 | template <class A> |
| 137 | class F1 { |
| 138 | public: |
| 139 | template <int B> |
| 140 | class Iterator { |
| 141 | }; |
| 142 | }; |
| 143 | |
| 144 | template<class T> |
| 145 | class F2 { |
| 146 | typename F1<T>:: /*template*/ Iterator<0> Mypos; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}} |
| 147 | }; |
| 148 | |
| 149 | template <class T> |
| 150 | void f(){ |
| 151 | typename F1<T>:: /*template*/ Iterator<0> Mypos; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}} |
| 152 | } |
| 153 | |
Anna Zaks | 6722155 | 2011-07-28 19:51:27 +0000 | [diff] [blame] | 154 | // Tests for &/* fixits radar 7113438. |
| 155 | class AD {}; |
| 156 | class BD: public AD {}; |
| 157 | |
| 158 | void test (BD &br) { |
| 159 | AD* aPtr; |
| 160 | BD b; |
| 161 | aPtr = b; // expected-error {{assigning to 'AD *' from incompatible type 'BD'; take the address with &}} |
Richard Smith | 98e13ea | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 162 | aPtr = br; // expected-error {{assigning to 'AD *' from incompatible type 'BD'; take the address with &}} |
Anna Zaks | 6722155 | 2011-07-28 19:51:27 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Richard Smith | d37b360 | 2012-02-10 11:05:11 +0000 | [diff] [blame^] | 165 | void foo1() const {} // expected-error {{non-member function cannot have 'const' qualifier}} |
| 166 | void foo2() volatile {} // expected-error {{non-member function cannot have 'volatile' qualifier}} |
| 167 | void foo3() const volatile {} // expected-error {{non-member function cannot have 'const volatile' qualifier}} |
Francois Pichet | 4147d30 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 168 | |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 169 | struct S { void f(int, char); }; |
| 170 | int itsAComma, |
| 171 | itsAComma2 = 0, |
Richard Smith | 98e13ea | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 172 | oopsAComma(42), // expected-error {{expected ';' at end of declaration}} |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 173 | AD oopsMoreCommas() { |
Richard Smith | 98e13ea | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 174 | static int n = 0, // expected-error {{expected ';' at end of declaration}} |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 175 | static char c, |
Richard Smith | 98e13ea | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 176 | &d = c, // expected-error {{expected ';' at end of declaration}} |
| 177 | S s, // expected-error {{expected ';' at end of declaration}} |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 178 | s.f(n, d); |
Richard Smith | 98e13ea | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 179 | AD ad, // expected-error {{expected ';' at end of declaration}} |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 180 | return ad; |
| 181 | } |
Richard Smith | 1c94c16 | 2012-01-09 22:31:44 +0000 | [diff] [blame] | 182 | struct MoreAccidentalCommas { |
| 183 | int a : 5, |
| 184 | b : 7, |
| 185 | : 4, // expected-error {{expected ';' at end of declaration}} |
| 186 | char c, // expected-error {{expected ';' at end of declaration}} |
| 187 | double d, // expected-error {{expected ';' at end of declaration}} |
| 188 | MoreAccidentalCommas *next, // expected-error {{expected ';' at end of declaration}} |
| 189 | public: |
| 190 | int k, // expected-error {{expected ';' at end of declaration}} |
| 191 | friend void f(MoreAccidentalCommas) {} |
| 192 | int k2, // expected-error {{expected ';' at end of declaration}} |
| 193 | virtual void g(), // expected-error {{expected ';' at end of declaration}} |
| 194 | }; |
Richard Smith | 874d253 | 2011-11-29 05:27:40 +0000 | [diff] [blame] | 195 | |
Richard Smith | 6e1fd33 | 2011-11-29 09:09:06 +0000 | [diff] [blame] | 196 | template<class T> struct Mystery; |
| 197 | template<class T> typedef Mystery<T>::type getMysteriousThing() { // \ |
| 198 | expected-error {{function definition declared 'typedef'}} \ |
| 199 | expected-error {{missing 'typename' prior to dependent}} |
| 200 | return Mystery<T>::get(); |
| 201 | } |