Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 1 | // RUN: cp %s %t |
| 2 | // RUN: %clang_cc1 -pedantic -Wall -fixit -x c++ %t || true |
| 3 | // RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror -x c++ %t |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 4 | |
| 5 | /* This is a test of the various code modification hints that are |
Douglas Gregor | fe057ac | 2009-04-02 03:20:30 +0000 | [diff] [blame] | 6 | provided as part of warning or extension diagnostics. All of the |
| 7 | warnings will be fixed by -fixit, and the resulting file should |
| 8 | compile cleanly with -Werror -pedantic. */ |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 9 | |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 10 | struct C1 { |
Douglas Gregor | a3a8351 | 2009-04-01 23:51:29 +0000 | [diff] [blame] | 11 | virtual void f(); |
| 12 | static void g(); |
| 13 | }; |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 14 | struct C2 : virtual public virtual C1 { }; // expected-error{{duplicate}} |
| 15 | |
Douglas Gregor | a3a8351 | 2009-04-01 23:51:29 +0000 | [diff] [blame] | 16 | virtual void C1::f() { } // expected-error{{'virtual' can only be specified inside the class definition}} |
| 17 | |
| 18 | static void C1::g() { } // expected-error{{'static' can only be specified inside the class definition}} |
| 19 | |
| 20 | template<int Value> struct CT { }; // expected-note{{previous use is here}} |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 21 | |
| 22 | CT<10 >> 2> ct; // expected-warning{{require parentheses}} |
Douglas Gregor | a3a8351 | 2009-04-01 23:51:29 +0000 | [diff] [blame] | 23 | |
| 24 | class C3 { |
| 25 | public: |
| 26 | C3(C3, int i = 0); // expected-error{{copy constructor must pass its first argument by reference}} |
| 27 | }; |
| 28 | |
| 29 | struct CT<0> { }; // expected-error{{'template<>'}} |
| 30 | |
| 31 | template<> class CT<1> { }; // expected-error{{tag type}} |
Anders Carlsson | ad26b73 | 2009-11-10 03:24:44 +0000 | [diff] [blame] | 32 | |
Douglas Gregor | 2848523 | 2010-02-01 23:46:27 +0000 | [diff] [blame] | 33 | // Access declarations |
| 34 | class A { |
| 35 | protected: |
| 36 | int foo(); |
| 37 | }; |
Anders Carlsson | ad26b73 | 2009-11-10 03:24:44 +0000 | [diff] [blame] | 38 | |
Douglas Gregor | 2848523 | 2010-02-01 23:46:27 +0000 | [diff] [blame] | 39 | class B : public A { |
| 40 | A::foo; // expected-warning{{access declarations are deprecated}} |
| 41 | }; |
Douglas Gregor | 2eef829 | 2010-03-24 07:14:45 +0000 | [diff] [blame] | 42 | |
| 43 | void f() throw(); |
| 44 | void f(); // expected-warning{{missing exception specification}} |
Douglas Gregor | 1aae80b | 2010-04-14 20:27:54 +0000 | [diff] [blame] | 45 | |
| 46 | namespace rdar7853795 { |
| 47 | struct A { |
| 48 | bool getNumComponents() const; // expected-note{{declared here}} |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 49 | void dump() const { |
Douglas Gregor | 1aae80b | 2010-04-14 20:27:54 +0000 | [diff] [blame] | 50 | getNumComponenets(); // expected-error{{use of undeclared identifier 'getNumComponenets'; did you mean 'getNumComponents'?}} |
| 51 | } |
| 52 | }; |
| 53 | } |
Douglas Gregor | b1f6fa4 | 2010-09-07 14:35:10 +0000 | [diff] [blame] | 54 | |
| 55 | namespace rdar7796492 { |
| 56 | class A { int x, y; A(); }; |
| 57 | |
| 58 | A::A() |
| 59 | : x(1) y(2) { // expected-error{{missing ',' between base or member initializers}} |
| 60 | } |
| 61 | |
| 62 | } |
Gabor Greif | a4a301d | 2010-09-08 00:31:13 +0000 | [diff] [blame] | 63 | |
| 64 | CT<1> main(void); // expected-error{{'main' must return 'int'}} |
| 65 | |
| 66 | // typedef CT<1> mainT(void); |
| 67 | // mainT main; // TODO |
| 68 | |
Francois Pichet | c71d8eb | 2010-10-01 21:19:28 +0000 | [diff] [blame] | 69 | // extra qualification on member |
| 70 | class C { |
| 71 | int C::foo(); |
| 72 | }; |
| 73 | |
Argyrios Kyrtzidis | a6eb5f8 | 2010-10-08 02:39:23 +0000 | [diff] [blame^] | 74 | namespace rdar8488464 { |
| 75 | int x == 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}} |
| 76 | |
| 77 | void f() { |
| 78 | int x == 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}} |
| 79 | (void)x; |
| 80 | if (int x == 0) { // expected-error {{invalid '==' at end of declaration; did you mean '='?}} |
| 81 | (void)x; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |