blob: 63726b9b6ef493c0f9411d1031b3c2d67434402c [file] [log] [blame]
Richard Smith6e1fd332011-11-29 09:09:06 +00001// RUN: %clang_cc1 -pedantic -Wall -Wno-comment -verify -fcxx-exceptions -x c++ %s
Nick Lewyckyba5f6ec2010-04-24 01:30:46 +00002// RUN: cp %s %t
Richard Smith6e1fd332011-11-29 09:09:06 +00003// 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 Gregor9b3064b2009-04-01 22:41:11 +00005
6/* This is a test of the various code modification hints that are
Douglas Gregorfe057ac2009-04-02 03:20:30 +00007 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 Gregor9b3064b2009-04-01 22:41:11 +000010
Nick Lewyckyba5f6ec2010-04-24 01:30:46 +000011struct C1 {
Douglas Gregora3a83512009-04-01 23:51:29 +000012 virtual void f();
13 static void g();
14};
Douglas Gregor9b3064b2009-04-01 22:41:11 +000015struct C2 : virtual public virtual C1 { }; // expected-error{{duplicate}}
16
Douglas Gregora3a83512009-04-01 23:51:29 +000017virtual void C1::f() { } // expected-error{{'virtual' can only be specified inside the class definition}}
18
19static void C1::g() { } // expected-error{{'static' can only be specified inside the class definition}}
20
21template<int Value> struct CT { }; // expected-note{{previous use is here}}
Douglas Gregor9b3064b2009-04-01 22:41:11 +000022
23CT<10 >> 2> ct; // expected-warning{{require parentheses}}
Douglas Gregora3a83512009-04-01 23:51:29 +000024
25class C3 {
26public:
27 C3(C3, int i = 0); // expected-error{{copy constructor must pass its first argument by reference}}
28};
29
30struct CT<0> { }; // expected-error{{'template<>'}}
31
Richard Smith98e13ea2011-10-20 01:41:28 +000032template<> union CT<1> { }; // expected-error{{tag type}}
Anders Carlssonad26b732009-11-10 03:24:44 +000033
Douglas Gregor28485232010-02-01 23:46:27 +000034// Access declarations
35class A {
36protected:
37 int foo();
38};
Anders Carlssonad26b732009-11-10 03:24:44 +000039
Douglas Gregor28485232010-02-01 23:46:27 +000040class B : public A {
41 A::foo; // expected-warning{{access declarations are deprecated}}
42};
Douglas Gregor2eef8292010-03-24 07:14:45 +000043
Richard Smith98e13ea2011-10-20 01:41:28 +000044void f() throw(); // expected-note{{previous}}
Douglas Gregor2eef8292010-03-24 07:14:45 +000045void f(); // expected-warning{{missing exception specification}}
Douglas Gregor1aae80b2010-04-14 20:27:54 +000046
47namespace rdar7853795 {
48 struct A {
49 bool getNumComponents() const; // expected-note{{declared here}}
Nick Lewyckyba5f6ec2010-04-24 01:30:46 +000050 void dump() const {
Douglas Gregor1aae80b2010-04-14 20:27:54 +000051 getNumComponenets(); // expected-error{{use of undeclared identifier 'getNumComponenets'; did you mean 'getNumComponents'?}}
52 }
53 };
54}
Douglas Gregorb1f6fa42010-09-07 14:35:10 +000055
56namespace 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 Greifa4a301d2010-09-08 00:31:13 +000064
Francois Pichetc71d8eb2010-10-01 21:19:28 +000065// extra qualification on member
66class C {
Richard Smith98e13ea2011-10-20 01:41:28 +000067 int C::foo(); // expected-warning {{extra qualification}}
Francois Pichetc71d8eb2010-10-01 21:19:28 +000068};
69
Argyrios Kyrtzidisa6eb5f82010-10-08 02:39:23 +000070namespace rdar8488464 {
71int x == 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}}
Richard Trieud6c7c672012-01-18 22:54:52 +000072int y += 0; // expected-error {{invalid '+=' at end of declaration; did you mean '='?}}
Argyrios Kyrtzidisa6eb5f82010-10-08 02:39:23 +000073
74void f() {
75 int x == 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}}
76 (void)x;
Richard Trieud6c7c672012-01-18 22:54:52 +000077 int y += 0; // expected-error {{invalid '+=' at end of declaration; did you mean '='?}}
78 (void)y;
Argyrios Kyrtzidisa6eb5f82010-10-08 02:39:23 +000079 if (int x == 0) { // expected-error {{invalid '==' at end of declaration; did you mean '='?}}
80 (void)x;
81 }
Richard Trieud6c7c672012-01-18 22:54:52 +000082 if (int y += 0) { // expected-error {{invalid '+=' at end of declaration; did you mean '='?}}
83 (void)y;
84 }
Argyrios Kyrtzidisa6eb5f82010-10-08 02:39:23 +000085}
86}
87
Francois Pichet4147d302011-03-27 19:41:34 +000088template <class A>
89class F1 {
90public:
91 template <int B>
92 class Iterator {
93 };
94};
95
96template<class T>
97class F2 {
98 typename F1<T>:: /*template*/ Iterator<0> Mypos; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
99};
100
101template <class T>
102void f(){
103 typename F1<T>:: /*template*/ Iterator<0> Mypos; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
104}
105
Anna Zaks67221552011-07-28 19:51:27 +0000106// Tests for &/* fixits radar 7113438.
107class AD {};
108class BD: public AD {};
109
110void test (BD &br) {
111 AD* aPtr;
112 BD b;
113 aPtr = b; // expected-error {{assigning to 'AD *' from incompatible type 'BD'; take the address with &}}
Richard Smith98e13ea2011-10-20 01:41:28 +0000114 aPtr = br; // expected-error {{assigning to 'AD *' from incompatible type 'BD'; take the address with &}}
Anna Zaks67221552011-07-28 19:51:27 +0000115}
116
Douglas Gregor43f51032011-10-19 06:04:55 +0000117void foo1() const {} // expected-error {{type qualifier is not allowed on this function}}
118void foo2() volatile {} // expected-error {{type qualifier is not allowed on this function}}
119void foo3() const volatile {} // expected-error {{type qualifier is not allowed on this function}}
Francois Pichet4147d302011-03-27 19:41:34 +0000120
Richard Smith0706df42011-10-19 21:33:05 +0000121struct S { void f(int, char); };
122int itsAComma,
123itsAComma2 = 0,
Richard Smith98e13ea2011-10-20 01:41:28 +0000124oopsAComma(42), // expected-error {{expected ';' at end of declaration}}
Richard Smith0706df42011-10-19 21:33:05 +0000125AD oopsMoreCommas() {
Richard Smith98e13ea2011-10-20 01:41:28 +0000126 static int n = 0, // expected-error {{expected ';' at end of declaration}}
Richard Smith0706df42011-10-19 21:33:05 +0000127 static char c,
Richard Smith98e13ea2011-10-20 01:41:28 +0000128 &d = c, // expected-error {{expected ';' at end of declaration}}
129 S s, // expected-error {{expected ';' at end of declaration}}
Richard Smith0706df42011-10-19 21:33:05 +0000130 s.f(n, d);
Richard Smith98e13ea2011-10-20 01:41:28 +0000131 AD ad, // expected-error {{expected ';' at end of declaration}}
Richard Smith0706df42011-10-19 21:33:05 +0000132 return ad;
133}
Richard Smith1c94c162012-01-09 22:31:44 +0000134struct MoreAccidentalCommas {
135 int a : 5,
136 b : 7,
137 : 4, // expected-error {{expected ';' at end of declaration}}
138 char c, // expected-error {{expected ';' at end of declaration}}
139 double d, // expected-error {{expected ';' at end of declaration}}
140 MoreAccidentalCommas *next, // expected-error {{expected ';' at end of declaration}}
141public:
142 int k, // expected-error {{expected ';' at end of declaration}}
143 friend void f(MoreAccidentalCommas) {}
144 int k2, // expected-error {{expected ';' at end of declaration}}
145 virtual void g(), // expected-error {{expected ';' at end of declaration}}
146};
Richard Smith874d2532011-11-29 05:27:40 +0000147
Richard Smith6e1fd332011-11-29 09:09:06 +0000148template<class T> struct Mystery;
149template<class T> typedef Mystery<T>::type getMysteriousThing() { // \
150 expected-error {{function definition declared 'typedef'}} \
151 expected-error {{missing 'typename' prior to dependent}}
152 return Mystery<T>::get();
153}