Paul Robinson | 80ba292 | 2016-12-21 18:33:17 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -pedantic -Wall -Wno-comment -verify -fcxx-exceptions -x c++ -std=c++98 %s |
| 2 | // RUN: cp %s %t-98 |
| 3 | // RUN: not %clang_cc1 -pedantic -Wall -Wno-comment -fcxx-exceptions -fixit -x c++ -std=c++98 %t-98 |
| 4 | // RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror -Wno-comment -fcxx-exceptions -x c++ -std=c++98 %t-98 |
Ismail Pazarbasi | 129c44c | 2014-09-25 21:13:02 +0000 | [diff] [blame] | 5 | // RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -x c++ -std=c++11 %s 2>&1 | FileCheck %s |
Paul Robinson | 80ba292 | 2016-12-21 18:33:17 +0000 | [diff] [blame] | 6 | // RUN: %clang_cc1 -pedantic -Wall -Wno-comment -verify -fcxx-exceptions -x c++ -std=c++11 %s |
| 7 | // RUN: cp %s %t-11 |
| 8 | // RUN: not %clang_cc1 -pedantic -Wall -Wno-comment -fcxx-exceptions -fixit -x c++ -std=c++11 %t-11 |
| 9 | // RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror -Wno-comment -fcxx-exceptions -x c++ -std=c++11 %t-11 |
Douglas Gregor | e3e01a2 | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 10 | |
| 11 | /* This is a test of the various code modification hints that are |
Douglas Gregor | 7e70204 | 2009-04-02 03:20:30 +0000 | [diff] [blame] | 12 | provided as part of warning or extension diagnostics. All of the |
| 13 | warnings will be fixed by -fixit, and the resulting file should |
| 14 | compile cleanly with -Werror -pedantic. */ |
Douglas Gregor | e3e01a2 | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 15 | |
Nick Lewycky | 784fad7 | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 16 | struct C1 { |
Douglas Gregor | 170512f | 2009-04-01 23:51:29 +0000 | [diff] [blame] | 17 | virtual void f(); |
| 18 | static void g(); |
| 19 | }; |
Douglas Gregor | e3e01a2 | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 20 | struct C2 : virtual public virtual C1 { }; // expected-error{{duplicate}} |
| 21 | |
Douglas Gregor | 170512f | 2009-04-01 23:51:29 +0000 | [diff] [blame] | 22 | virtual void C1::f() { } // expected-error{{'virtual' can only be specified inside the class definition}} |
| 23 | |
| 24 | static void C1::g() { } // expected-error{{'static' can only be specified inside the class definition}} |
| 25 | |
Richard Smith | 4b55a9c | 2014-04-17 03:29:33 +0000 | [diff] [blame] | 26 | template<int Value> struct CT { template<typename> struct Inner; }; // expected-note{{previous use is here}} |
Douglas Gregor | e3e01a2 | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 27 | |
Paul Robinson | 80ba292 | 2016-12-21 18:33:17 +0000 | [diff] [blame] | 28 | // FIXME: In C++11 this gets 'expected unqualified-id' which fixit can't fix. |
| 29 | // Probably parses as `CT<10> > 2 > ct;` rather than `CT<(10 >> 2)> ct;`. |
| 30 | #if __cplusplus < 201103L |
Douglas Gregor | e3e01a2 | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 31 | CT<10 >> 2> ct; // expected-warning{{require parentheses}} |
Paul Robinson | 80ba292 | 2016-12-21 18:33:17 +0000 | [diff] [blame] | 32 | #endif |
Douglas Gregor | 170512f | 2009-04-01 23:51:29 +0000 | [diff] [blame] | 33 | |
| 34 | class C3 { |
| 35 | public: |
| 36 | C3(C3, int i = 0); // expected-error{{copy constructor must pass its first argument by reference}} |
| 37 | }; |
| 38 | |
| 39 | struct CT<0> { }; // expected-error{{'template<>'}} |
| 40 | |
Richard Smith | 4e9ea71 | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 41 | template<> union CT<1> { }; // expected-error{{tag type}} |
Anders Carlsson | 0b8ea55 | 2009-11-10 03:24:44 +0000 | [diff] [blame] | 42 | |
Richard Smith | 4b55a9c | 2014-04-17 03:29:33 +0000 | [diff] [blame] | 43 | struct CT<2>::Inner<int> { }; // expected-error 2{{'template<>'}} |
| 44 | |
Douglas Gregor | f1d70ad | 2010-02-01 23:46:27 +0000 | [diff] [blame] | 45 | // Access declarations |
| 46 | class A { |
| 47 | protected: |
| 48 | int foo(); |
| 49 | }; |
Anders Carlsson | 0b8ea55 | 2009-11-10 03:24:44 +0000 | [diff] [blame] | 50 | |
Douglas Gregor | f1d70ad | 2010-02-01 23:46:27 +0000 | [diff] [blame] | 51 | class B : public A { |
Paul Robinson | 80ba292 | 2016-12-21 18:33:17 +0000 | [diff] [blame] | 52 | #if __cplusplus >= 201103L |
| 53 | A::foo; // expected-error{{ISO C++11 does not allow access declarations}} |
| 54 | #else |
Douglas Gregor | f1d70ad | 2010-02-01 23:46:27 +0000 | [diff] [blame] | 55 | A::foo; // expected-warning{{access declarations are deprecated}} |
Paul Robinson | 80ba292 | 2016-12-21 18:33:17 +0000 | [diff] [blame] | 56 | #endif |
Douglas Gregor | f1d70ad | 2010-02-01 23:46:27 +0000 | [diff] [blame] | 57 | }; |
Douglas Gregor | d6bc5e6 | 2010-03-24 07:14:45 +0000 | [diff] [blame] | 58 | |
Richard Smith | 4e9ea71 | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 59 | void f() throw(); // expected-note{{previous}} |
Richard Smith | a91de37 | 2015-09-30 00:48:50 +0000 | [diff] [blame] | 60 | void f(); // expected-error{{missing exception specification}} |
Douglas Gregor | 2fb18b7 | 2010-04-14 20:27:54 +0000 | [diff] [blame] | 61 | |
| 62 | namespace rdar7853795 { |
| 63 | struct A { |
| 64 | bool getNumComponents() const; // expected-note{{declared here}} |
Nick Lewycky | 784fad7 | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 65 | void dump() const { |
Douglas Gregor | 2fb18b7 | 2010-04-14 20:27:54 +0000 | [diff] [blame] | 66 | getNumComponenets(); // expected-error{{use of undeclared identifier 'getNumComponenets'; did you mean 'getNumComponents'?}} |
| 67 | } |
| 68 | }; |
| 69 | } |
Douglas Gregor | 3465e26 | 2010-09-07 14:35:10 +0000 | [diff] [blame] | 70 | |
| 71 | namespace rdar7796492 { |
Benjamin Kramer | 697067f | 2012-06-11 16:06:57 +0000 | [diff] [blame] | 72 | struct A { int x, y; A(); }; |
Douglas Gregor | 3465e26 | 2010-09-07 14:35:10 +0000 | [diff] [blame] | 73 | |
| 74 | A::A() |
| 75 | : x(1) y(2) { // expected-error{{missing ',' between base or member initializers}} |
| 76 | } |
| 77 | |
| 78 | } |
Gabor Greif | 80c2183 | 2010-09-08 00:31:13 +0000 | [diff] [blame] | 79 | |
Francois Pichet | 6d76e6c | 2010-10-01 21:19:28 +0000 | [diff] [blame] | 80 | // extra qualification on member |
| 81 | class C { |
Douglas Gregor | 43bc036 | 2012-09-13 20:16:20 +0000 | [diff] [blame] | 82 | int C::foo(); // expected-error {{extra qualification}} |
Francois Pichet | 6d76e6c | 2010-10-01 21:19:28 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
Argyrios Kyrtzidis | b5c7c51 | 2010-10-08 02:39:23 +0000 | [diff] [blame] | 85 | namespace rdar8488464 { |
Richard Trieu | 4972a6d | 2012-01-19 22:01:51 +0000 | [diff] [blame] | 86 | int x = 0; |
| 87 | int x1 &= 0; // expected-error {{invalid '&=' at end of declaration; did you mean '='?}} |
| 88 | int x2 *= 0; // expected-error {{invalid '*=' at end of declaration; did you mean '='?}} |
| 89 | int x3 += 0; // expected-error {{invalid '+=' at end of declaration; did you mean '='?}} |
| 90 | int x4 -= 0; // expected-error {{invalid '-=' at end of declaration; did you mean '='?}} |
| 91 | int x5 != 0; // expected-error {{invalid '!=' at end of declaration; did you mean '='?}} |
| 92 | int x6 /= 0; // expected-error {{invalid '/=' at end of declaration; did you mean '='?}} |
| 93 | int x7 %= 0; // expected-error {{invalid '%=' at end of declaration; did you mean '='?}} |
| 94 | int x8 <= 0; // expected-error {{invalid '<=' at end of declaration; did you mean '='?}} |
| 95 | int x9 <<= 0; // expected-error {{invalid '<<=' at end of declaration; did you mean '='?}} |
| 96 | int x10 >= 0; // expected-error {{invalid '>=' at end of declaration; did you mean '='?}} |
| 97 | int x11 >>= 0; // expected-error {{invalid '>>=' at end of declaration; did you mean '='?}} |
| 98 | int x12 ^= 0; // expected-error {{invalid '^=' at end of declaration; did you mean '='?}} |
| 99 | int x13 |= 0; // expected-error {{invalid '|=' at end of declaration; did you mean '='?}} |
| 100 | int x14 == 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}} |
Argyrios Kyrtzidis | b5c7c51 | 2010-10-08 02:39:23 +0000 | [diff] [blame] | 101 | |
| 102 | void f() { |
Richard Trieu | 4972a6d | 2012-01-19 22:01:51 +0000 | [diff] [blame] | 103 | int x = 0; |
Argyrios Kyrtzidis | b5c7c51 | 2010-10-08 02:39:23 +0000 | [diff] [blame] | 104 | (void)x; |
Richard Trieu | 4972a6d | 2012-01-19 22:01:51 +0000 | [diff] [blame] | 105 | int x1 &= 0; // expected-error {{invalid '&=' at end of declaration; did you mean '='?}} |
| 106 | (void)x1; |
| 107 | int x2 *= 0; // expected-error {{invalid '*=' at end of declaration; did you mean '='?}} |
| 108 | (void)x2; |
| 109 | int x3 += 0; // expected-error {{invalid '+=' at end of declaration; did you mean '='?}} |
| 110 | (void)x3; |
| 111 | int x4 -= 0; // expected-error {{invalid '-=' at end of declaration; did you mean '='?}} |
| 112 | (void)x4; |
| 113 | int x5 != 0; // expected-error {{invalid '!=' at end of declaration; did you mean '='?}} |
| 114 | (void)x5; |
| 115 | int x6 /= 0; // expected-error {{invalid '/=' at end of declaration; did you mean '='?}} |
| 116 | (void)x6; |
| 117 | int x7 %= 0; // expected-error {{invalid '%=' at end of declaration; did you mean '='?}} |
| 118 | (void)x7; |
| 119 | int x8 <= 0; // expected-error {{invalid '<=' at end of declaration; did you mean '='?}} |
| 120 | (void)x8; |
| 121 | int x9 <<= 0; // expected-error {{invalid '<<=' at end of declaration; did you mean '='?}} |
| 122 | (void)x9; |
| 123 | int x10 >= 0; // expected-error {{invalid '>=' at end of declaration; did you mean '='?}} |
| 124 | (void)x10; |
| 125 | int x11 >>= 0; // expected-error {{invalid '>>=' at end of declaration; did you mean '='?}} |
| 126 | (void)x11; |
| 127 | int x12 ^= 0; // expected-error {{invalid '^=' at end of declaration; did you mean '='?}} |
| 128 | (void)x12; |
| 129 | int x13 |= 0; // expected-error {{invalid '|=' at end of declaration; did you mean '='?}} |
| 130 | (void)x13; |
| 131 | int x14 == 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}} |
| 132 | (void)x14; |
| 133 | if (int x = 0) { (void)x; } |
| 134 | if (int x1 &= 0) { (void)x1; } // expected-error {{invalid '&=' at end of declaration; did you mean '='?}} |
| 135 | if (int x2 *= 0) { (void)x2; } // expected-error {{invalid '*=' at end of declaration; did you mean '='?}} |
| 136 | if (int x3 += 0) { (void)x3; } // expected-error {{invalid '+=' at end of declaration; did you mean '='?}} |
| 137 | if (int x4 -= 0) { (void)x4; } // expected-error {{invalid '-=' at end of declaration; did you mean '='?}} |
| 138 | if (int x5 != 0) { (void)x5; } // expected-error {{invalid '!=' at end of declaration; did you mean '='?}} |
| 139 | if (int x6 /= 0) { (void)x6; } // expected-error {{invalid '/=' at end of declaration; did you mean '='?}} |
| 140 | if (int x7 %= 0) { (void)x7; } // expected-error {{invalid '%=' at end of declaration; did you mean '='?}} |
| 141 | if (int x8 <= 0) { (void)x8; } // expected-error {{invalid '<=' at end of declaration; did you mean '='?}} |
| 142 | if (int x9 <<= 0) { (void)x9; } // expected-error {{invalid '<<=' at end of declaration; did you mean '='?}} |
| 143 | if (int x10 >= 0) { (void)x10; } // expected-error {{invalid '>=' at end of declaration; did you mean '='?}} |
| 144 | if (int x11 >>= 0) { (void)x11; } // expected-error {{invalid '>>=' at end of declaration; did you mean '='?}} |
| 145 | if (int x12 ^= 0) { (void)x12; } // expected-error {{invalid '^=' at end of declaration; did you mean '='?}} |
| 146 | if (int x13 |= 0) { (void)x13; } // expected-error {{invalid '|=' at end of declaration; did you mean '='?}} |
| 147 | if (int x14 == 0) { (void)x14; } // expected-error {{invalid '==' at end of declaration; did you mean '='?}} |
Argyrios Kyrtzidis | b5c7c51 | 2010-10-08 02:39:23 +0000 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | |
Francois Pichet | 4e7a2c0 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 151 | template <class A> |
| 152 | class F1 { |
| 153 | public: |
| 154 | template <int B> |
| 155 | class Iterator { |
| 156 | }; |
| 157 | }; |
| 158 | |
| 159 | template<class T> |
| 160 | class F2 { |
| 161 | typename F1<T>:: /*template*/ Iterator<0> Mypos; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}} |
| 162 | }; |
| 163 | |
| 164 | template <class T> |
| 165 | void f(){ |
| 166 | typename F1<T>:: /*template*/ Iterator<0> Mypos; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}} |
| 167 | } |
| 168 | |
Anna Zaks | 3b40271 | 2011-07-28 19:51:27 +0000 | [diff] [blame] | 169 | // Tests for &/* fixits radar 7113438. |
| 170 | class AD {}; |
| 171 | class BD: public AD {}; |
| 172 | |
| 173 | void test (BD &br) { |
| 174 | AD* aPtr; |
| 175 | BD b; |
| 176 | aPtr = b; // expected-error {{assigning to 'AD *' from incompatible type 'BD'; take the address with &}} |
Richard Smith | 4e9ea71 | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 177 | aPtr = br; // expected-error {{assigning to 'AD *' from incompatible type 'BD'; take the address with &}} |
Anna Zaks | 3b40271 | 2011-07-28 19:51:27 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Richard Smith | 63168c7 | 2012-02-10 11:05:11 +0000 | [diff] [blame] | 180 | void foo1() const {} // expected-error {{non-member function cannot have 'const' qualifier}} |
| 181 | void foo2() volatile {} // expected-error {{non-member function cannot have 'volatile' qualifier}} |
| 182 | void foo3() const volatile {} // expected-error {{non-member function cannot have 'const volatile' qualifier}} |
Francois Pichet | 4e7a2c0 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 183 | |
Richard Smith | 09f76ee | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 184 | struct S { void f(int, char); }; |
| 185 | int itsAComma, |
| 186 | itsAComma2 = 0, |
Richard Smith | 4e9ea71 | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 187 | oopsAComma(42), // expected-error {{expected ';' at end of declaration}} |
Richard Smith | 09f76ee | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 188 | AD oopsMoreCommas() { |
Richard Smith | 4e9ea71 | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 189 | static int n = 0, // expected-error {{expected ';' at end of declaration}} |
Richard Smith | 09f76ee | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 190 | static char c, |
Richard Smith | 4e9ea71 | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 191 | &d = c, // expected-error {{expected ';' at end of declaration}} |
| 192 | S s, // expected-error {{expected ';' at end of declaration}} |
Richard Smith | 09f76ee | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 193 | s.f(n, d); |
Richard Smith | 4e9ea71 | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 194 | AD ad, // expected-error {{expected ';' at end of declaration}} |
Richard Smith | 09f76ee | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 195 | return ad; |
| 196 | } |
Richard Smith | c8a7903 | 2012-01-09 22:31:44 +0000 | [diff] [blame] | 197 | struct MoreAccidentalCommas { |
| 198 | int a : 5, |
| 199 | b : 7, |
| 200 | : 4, // expected-error {{expected ';' at end of declaration}} |
| 201 | char c, // expected-error {{expected ';' at end of declaration}} |
| 202 | double d, // expected-error {{expected ';' at end of declaration}} |
| 203 | MoreAccidentalCommas *next, // expected-error {{expected ';' at end of declaration}} |
| 204 | public: |
| 205 | int k, // expected-error {{expected ';' at end of declaration}} |
| 206 | friend void f(MoreAccidentalCommas) {} |
| 207 | int k2, // expected-error {{expected ';' at end of declaration}} |
| 208 | virtual void g(), // expected-error {{expected ';' at end of declaration}} |
| 209 | }; |
Richard Smith | 675ea99 | 2011-11-29 05:27:40 +0000 | [diff] [blame] | 210 | |
Richard Smith | 5371160 | 2011-11-29 09:09:06 +0000 | [diff] [blame] | 211 | template<class T> struct Mystery; |
| 212 | template<class T> typedef Mystery<T>::type getMysteriousThing() { // \ |
| 213 | expected-error {{function definition declared 'typedef'}} \ |
| 214 | expected-error {{missing 'typename' prior to dependent}} |
| 215 | return Mystery<T>::get(); |
| 216 | } |
David Blaikie | f221e51 | 2012-04-02 19:15:28 +0000 | [diff] [blame] | 217 | |
David Blaikie | 3697983 | 2012-04-06 06:28:32 +0000 | [diff] [blame] | 218 | template<template<typename> Foo, // expected-error {{template template parameter requires 'class' after the parameter list}} |
Richard Smith | cbaaa29 | 2017-08-13 22:26:53 +0000 | [diff] [blame] | 219 | template<typename> typename Bar, // expected-warning {{template template parameter using 'typename' is a C++17 extension}} |
David Blaikie | 3697983 | 2012-04-06 06:28:32 +0000 | [diff] [blame] | 220 | template<typename> struct Baz> // expected-error {{template template parameter requires 'class' after the parameter list}} |
David Blaikie | f221e51 | 2012-04-02 19:15:28 +0000 | [diff] [blame] | 221 | void func(); |
Kaelyn Uhrain | b3967d7 | 2012-04-19 23:17:45 +0000 | [diff] [blame] | 222 | |
Kaelyn Uhrain | b3967d7 | 2012-04-19 23:17:45 +0000 | [diff] [blame] | 223 | namespace ShadowedTagType { |
| 224 | class Foo { |
| 225 | public: |
| 226 | enum Bar { X, Y }; |
| 227 | void SetBar(Bar bar); |
Kaelyn Uhrain | 3fe3f85 | 2012-04-27 18:26:49 +0000 | [diff] [blame] | 228 | Bar Bar(); // expected-note 2 {{enum 'Bar' is hidden by a non-type declaration of 'Bar' here}} |
Kaelyn Uhrain | b3967d7 | 2012-04-19 23:17:45 +0000 | [diff] [blame] | 229 | private: |
| 230 | Bar bar_; // expected-error {{must use 'enum' tag to refer to type 'Bar' in this scope}} |
| 231 | }; |
| 232 | void Foo::SetBar(Bar bar) { bar_ = bar; } // expected-error {{must use 'enum' tag to refer to type 'Bar' in this scope}} |
Kaelyn Uhrain | d783617 | 2012-04-19 23:26:12 +0000 | [diff] [blame] | 233 | } |
Kaelyn Uhrain | 76e0734 | 2012-04-25 19:49:54 +0000 | [diff] [blame] | 234 | |
David Blaikie | 7665a62 | 2012-04-30 18:27:22 +0000 | [diff] [blame] | 235 | #define NULL __null |
| 236 | char c = NULL; // expected-warning {{implicit conversion of NULL constant to 'char'}} |
David Blaikie | 9366d2b | 2012-06-19 21:19:06 +0000 | [diff] [blame] | 237 | double dbl = NULL; // expected-warning {{implicit conversion of NULL constant to 'double'}} |
David Blaikie | 7665a62 | 2012-04-30 18:27:22 +0000 | [diff] [blame] | 238 | |
Kaelyn Uhrain | 76e0734 | 2012-04-25 19:49:54 +0000 | [diff] [blame] | 239 | namespace arrow_suggest { |
| 240 | |
| 241 | template <typename T> |
| 242 | class wrapped_ptr { |
| 243 | public: |
| 244 | wrapped_ptr(T* ptr) : ptr_(ptr) {} |
| 245 | T* operator->() { return ptr_; } |
| 246 | private: |
| 247 | T *ptr_; |
| 248 | }; |
| 249 | |
| 250 | class Worker { |
| 251 | public: |
| 252 | void DoSomething(); |
| 253 | }; |
| 254 | |
| 255 | void test() { |
| 256 | wrapped_ptr<Worker> worker(new Worker); |
| 257 | worker.DoSomething(); // expected-error {{no member named 'DoSomething' in 'arrow_suggest::wrapped_ptr<arrow_suggest::Worker>'; did you mean to use '->' instead of '.'?}} |
| 258 | } |
| 259 | |
| 260 | } // namespace arrow_suggest |
Kaelyn Uhrain | 1dac08d | 2012-06-07 23:57:12 +0000 | [diff] [blame] | 261 | |
| 262 | // Make sure fixing namespace-qualified identifiers functions properly with |
| 263 | // namespace-aware typo correction/ |
| 264 | namespace redecl_typo { |
| 265 | namespace Foo { |
| 266 | void BeEvil(); // expected-note {{'BeEvil' declared here}} |
| 267 | } |
| 268 | namespace Bar { |
| 269 | namespace Foo { |
| 270 | bool isGood(); // expected-note {{'Bar::Foo::isGood' declared here}} |
| 271 | void beEvil(); |
| 272 | } |
| 273 | } |
| 274 | bool Foo::isGood() { // expected-error {{out-of-line definition of 'isGood' does not match any declaration in namespace 'redecl_typo::Foo'; did you mean 'Bar::Foo::isGood'?}} |
| 275 | return true; |
| 276 | } |
| 277 | void Foo::beEvil() {} // expected-error {{out-of-line definition of 'beEvil' does not match any declaration in namespace 'redecl_typo::Foo'; did you mean 'BeEvil'?}} |
| 278 | } |
Richard Smith | 7b3f322 | 2012-06-18 06:11:04 +0000 | [diff] [blame] | 279 | |
| 280 | // Test behavior when a template-id is ended by a token which starts with '>'. |
| 281 | namespace greatergreater { |
| 282 | template<typename T> struct S { S(); S(T); }; |
| 283 | void f(S<int>=0); // expected-error {{a space is required between a right angle bracket and an equals sign (use '> =')}} |
| 284 | |
| 285 | // FIXME: The fix-its here overlap so -fixit mode can't apply the second one. |
| 286 | //void f(S<S<int>>=S<int>()); |
| 287 | |
| 288 | struct Shr { |
| 289 | template<typename T> Shr(T); |
| 290 | template<typename T> void operator >>=(T); |
| 291 | }; |
| 292 | |
| 293 | template<template<typename>> struct TemplateTemplateParam; // expected-error {{requires 'class'}} |
| 294 | |
| 295 | template<typename T> void t(); |
| 296 | void g() { |
| 297 | void (*p)() = &t<int>; |
| 298 | (void)(&t<int>==p); // expected-error {{use '> ='}} |
| 299 | (void)(&t<int>>=p); // expected-error {{use '> >'}} |
Paul Robinson | 80ba292 | 2016-12-21 18:33:17 +0000 | [diff] [blame] | 300 | #if __cplusplus < 201103L |
Richard Smith | 7b3f322 | 2012-06-18 06:11:04 +0000 | [diff] [blame] | 301 | (void)(&t<S<int>>>=p); // expected-error {{use '> >'}} |
| 302 | (Shr)&t<S<int>>>>=p; // expected-error {{use '> >'}} |
Paul Robinson | 80ba292 | 2016-12-21 18:33:17 +0000 | [diff] [blame] | 303 | #endif |
Richard Smith | 7b3f322 | 2012-06-18 06:11:04 +0000 | [diff] [blame] | 304 | |
| 305 | // FIXME: We correct this to '&t<int> > >= p;' not '&t<int> >>= p;' |
| 306 | //(Shr)&t<int>>>=p; |
| 307 | |
| 308 | // FIXME: The fix-its here overlap. |
| 309 | //(void)(&t<S<int>>==p); |
| 310 | } |
| 311 | } |
David Blaikie | c2ff8e1 | 2012-10-11 22:55:07 +0000 | [diff] [blame] | 312 | |
| 313 | class foo { |
| 314 | static void test() { |
| 315 | (void)&i; // expected-error{{must explicitly qualify name of member function when taking its address}} |
| 316 | } |
| 317 | int i(); |
| 318 | }; |
David Blaikie | 5e026f5 | 2013-03-20 17:42:13 +0000 | [diff] [blame] | 319 | |
| 320 | namespace dtor_fixit { |
| 321 | class foo { |
| 322 | ~bar() { } // expected-error {{expected the class name after '~' to name a destructor}} |
| 323 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:6-[[@LINE-1]]:9}:"foo" |
| 324 | }; |
Richard Smith | efa6f73 | 2014-09-06 02:06:12 +0000 | [diff] [blame] | 325 | |
| 326 | class bar { |
| 327 | ~bar(); |
| 328 | }; |
| 329 | ~bar::bar() {} // expected-error {{'~' in destructor name should be after nested name specifier}} |
| 330 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:4}:"" |
| 331 | // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:9-[[@LINE-2]]:9}:"~" |
David Blaikie | 5e026f5 | 2013-03-20 17:42:13 +0000 | [diff] [blame] | 332 | } |
Richard Smith | 9ce302e | 2013-07-11 05:10:21 +0000 | [diff] [blame] | 333 | |
| 334 | namespace PR5066 { |
| 335 | template<typename T> struct X {}; |
| 336 | X<int *p> x; // expected-error {{type-id cannot have a name}} |
| 337 | } |
Kaelyn Uhrain | 1bb5dbf | 2013-07-11 22:38:30 +0000 | [diff] [blame] | 338 | |
Kaelyn Uhrain | 638264e | 2013-07-12 21:43:02 +0000 | [diff] [blame] | 339 | namespace PR5898 { |
| 340 | class A { |
| 341 | public: |
| 342 | const char *str(); |
| 343 | }; |
| 344 | const char* foo(A &x) |
| 345 | { |
| 346 | return x.str.(); // expected-error {{unexpected '.' in function call; perhaps remove the '.'?}} |
| 347 | } |
| 348 | bool bar(A x, const char *y) { |
| 349 | return foo->(x) == y; // expected-error {{unexpected '->' in function call; perhaps remove the '->'?}} |
| 350 | } |
| 351 | } |
Kaelyn Uhrain | 957c8b1 | 2013-07-31 20:16:17 +0000 | [diff] [blame] | 352 | |
| 353 | namespace PR15045 { |
| 354 | class Cl0 { |
| 355 | public: |
| 356 | int a; |
| 357 | }; |
| 358 | |
| 359 | int f() { |
| 360 | Cl0 c; |
Eric Christopher | 6e11073 | 2015-04-02 22:10:06 +0000 | [diff] [blame] | 361 | return c->a; // expected-error {{member reference type 'PR15045::Cl0' is not a pointer; did you mean to use '.'?}} |
Kaelyn Uhrain | 957c8b1 | 2013-07-31 20:16:17 +0000 | [diff] [blame] | 362 | } |
| 363 | } |
Ismail Pazarbasi | 129c44c | 2014-09-25 21:13:02 +0000 | [diff] [blame] | 364 | |
| 365 | namespace curly_after_base_clause { |
| 366 | struct A { void f(); }; |
| 367 | struct B : A // expected-error{{expected '{' after base class list}} |
| 368 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:" {" |
| 369 | int i; |
| 370 | }; |
| 371 | struct C : A // expected-error{{expected '{' after base class list}} |
| 372 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:" {" |
| 373 | using A::f; |
| 374 | }; |
| 375 | struct D : A // expected-error{{expected '{' after base class list}} |
| 376 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:" {" |
| 377 | protected: |
| 378 | }; |
| 379 | struct E : A // expected-error{{expected '{' after base class list}} |
| 380 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:" {" |
| 381 | template<typename T> struct inner { }; |
| 382 | }; |
| 383 | struct F : A // expected-error{{expected '{' after base class list}} |
| 384 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:" {" |
| 385 | F() { } |
| 386 | }; |
| 387 | #if __cplusplus >= 201103L |
| 388 | struct G : A // expected-error{{expected '{' after base class list}} |
| 389 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:" {" |
| 390 | constexpr G(int) { } |
| 391 | }; |
| 392 | struct H : A // expected-error{{expected '{' after base class list}} |
| 393 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:" {" |
| 394 | static_assert(true, ""); |
| 395 | }; |
| 396 | #endif |
| 397 | } |
Richard Smith | a865a16 | 2014-12-19 02:07:47 +0000 | [diff] [blame] | 398 | |
| 399 | struct conversion_operator { |
| 400 | conversion_operator::* const operator int(); // expected-error {{put the complete type after 'operator'}} |
| 401 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:32}:"" |
| 402 | // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:44-[[@LINE-2]]:44}:" conversion_operator::* const" |
| 403 | }; |
Nico Weber | 337d5aa | 2015-04-17 08:32:38 +0000 | [diff] [blame] | 404 | |
| 405 | struct const_zero_init { |
| 406 | int a; |
| 407 | }; |
| 408 | const const_zero_init czi; // expected-error {{default initialization of an object of const type 'const const_zero_init'}} |
| 409 | // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:26-[[@LINE-1]]:26}:"{}" |
| 410 | int use_czi = czi.a; |
| 411 | |
Alex Lorenz | 56fb6fe | 2017-01-20 15:38:58 +0000 | [diff] [blame] | 412 | namespace dotPointerDestructor { |
| 413 | |
| 414 | struct Bar { |
| 415 | ~Bar(); |
| 416 | }; |
| 417 | |
| 418 | void bar(Bar *o) { |
| 419 | o.~Bar(); // expected-error {{member reference type 'dotPointerDestructor::Bar *' is a pointer; did you mean to use '->'}} |
| 420 | } // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:4-[[@LINE-1]]:5}:"->" |
| 421 | |
| 422 | } |