Richard Smith | 98e13ea | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -pedantic -Wall -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 | 98e13ea | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 3 | // RUN: not %clang_cc1 -pedantic -Wall -fcxx-exceptions -fixit -x c++ %t |
| 4 | // RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror -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 { |
| 71 | int x == 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}} |
| 72 | |
| 73 | void f() { |
| 74 | int x == 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}} |
| 75 | (void)x; |
| 76 | if (int x == 0) { // expected-error {{invalid '==' at end of declaration; did you mean '='?}} |
| 77 | (void)x; |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
Francois Pichet | 4147d30 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 82 | template <class A> |
| 83 | class F1 { |
| 84 | public: |
| 85 | template <int B> |
| 86 | class Iterator { |
| 87 | }; |
| 88 | }; |
| 89 | |
| 90 | template<class T> |
| 91 | class F2 { |
| 92 | typename F1<T>:: /*template*/ Iterator<0> Mypos; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}} |
| 93 | }; |
| 94 | |
| 95 | template <class T> |
| 96 | void f(){ |
| 97 | typename F1<T>:: /*template*/ Iterator<0> Mypos; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}} |
| 98 | } |
| 99 | |
Anna Zaks | 6722155 | 2011-07-28 19:51:27 +0000 | [diff] [blame] | 100 | // Tests for &/* fixits radar 7113438. |
| 101 | class AD {}; |
| 102 | class BD: public AD {}; |
| 103 | |
| 104 | void test (BD &br) { |
| 105 | AD* aPtr; |
| 106 | BD b; |
| 107 | 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] | 108 | 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] | 109 | } |
| 110 | |
Douglas Gregor | 43f5103 | 2011-10-19 06:04:55 +0000 | [diff] [blame] | 111 | void foo1() const {} // expected-error {{type qualifier is not allowed on this function}} |
| 112 | void foo2() volatile {} // expected-error {{type qualifier is not allowed on this function}} |
| 113 | void foo3() const volatile {} // expected-error {{type qualifier is not allowed on this function}} |
Francois Pichet | 4147d30 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 114 | |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 115 | struct S { void f(int, char); }; |
| 116 | int itsAComma, |
| 117 | itsAComma2 = 0, |
Richard Smith | 98e13ea | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 118 | oopsAComma(42), // expected-error {{expected ';' at end of declaration}} |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 119 | AD oopsMoreCommas() { |
Richard Smith | 98e13ea | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 120 | static int n = 0, // expected-error {{expected ';' at end of declaration}} |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 121 | static char c, |
Richard Smith | 98e13ea | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 122 | &d = c, // expected-error {{expected ';' at end of declaration}} |
| 123 | S s, // expected-error {{expected ';' at end of declaration}} |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 124 | s.f(n, d); |
Richard Smith | 98e13ea | 2011-10-20 01:41:28 +0000 | [diff] [blame] | 125 | AD ad, // expected-error {{expected ';' at end of declaration}} |
Richard Smith | 0706df4 | 2011-10-19 21:33:05 +0000 | [diff] [blame] | 126 | return ad; |
| 127 | } |