blob: 86b397777c2a7b6cd37ad685576368f1bd0ec78c [file] [log] [blame]
Richard Smith98e13ea2011-10-20 01:41:28 +00001// RUN: %clang_cc1 -pedantic -Wall -verify -fcxx-exceptions -x c++ %s
Nick Lewyckyba5f6ec2010-04-24 01:30:46 +00002// RUN: cp %s %t
Richard Smith98e13ea2011-10-20 01:41:28 +00003// 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 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 '='?}}
72
73void 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 Pichet4147d302011-03-27 19:41:34 +000082template <class A>
83class F1 {
84public:
85 template <int B>
86 class Iterator {
87 };
88};
89
90template<class T>
91class F2 {
92 typename F1<T>:: /*template*/ Iterator<0> Mypos; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
93};
94
95template <class T>
96void 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 Zaks67221552011-07-28 19:51:27 +0000100// Tests for &/* fixits radar 7113438.
101class AD {};
102class BD: public AD {};
103
104void 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 Smith98e13ea2011-10-20 01:41:28 +0000108 aPtr = br; // expected-error {{assigning to 'AD *' from incompatible type 'BD'; take the address with &}}
Anna Zaks67221552011-07-28 19:51:27 +0000109}
110
Douglas Gregor43f51032011-10-19 06:04:55 +0000111void foo1() const {} // expected-error {{type qualifier is not allowed on this function}}
112void foo2() volatile {} // expected-error {{type qualifier is not allowed on this function}}
113void foo3() const volatile {} // expected-error {{type qualifier is not allowed on this function}}
Francois Pichet4147d302011-03-27 19:41:34 +0000114
Richard Smith0706df42011-10-19 21:33:05 +0000115struct S { void f(int, char); };
116int itsAComma,
117itsAComma2 = 0,
Richard Smith98e13ea2011-10-20 01:41:28 +0000118oopsAComma(42), // expected-error {{expected ';' at end of declaration}}
Richard Smith0706df42011-10-19 21:33:05 +0000119AD oopsMoreCommas() {
Richard Smith98e13ea2011-10-20 01:41:28 +0000120 static int n = 0, // expected-error {{expected ';' at end of declaration}}
Richard Smith0706df42011-10-19 21:33:05 +0000121 static char c,
Richard Smith98e13ea2011-10-20 01:41:28 +0000122 &d = c, // expected-error {{expected ';' at end of declaration}}
123 S s, // expected-error {{expected ';' at end of declaration}}
Richard Smith0706df42011-10-19 21:33:05 +0000124 s.f(n, d);
Richard Smith98e13ea2011-10-20 01:41:28 +0000125 AD ad, // expected-error {{expected ';' at end of declaration}}
Richard Smith0706df42011-10-19 21:33:05 +0000126 return ad;
127}