blob: 109c14d91a702e7c38cad7b5fa30a64ba6d58273 [file] [log] [blame]
Nick Lewyckyba5f6ec2010-04-24 01:30:46 +00001// 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 Gregor9b3064b2009-04-01 22:41:11 +00004
5/* This is a test of the various code modification hints that are
Douglas Gregorfe057ac2009-04-02 03:20:30 +00006 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 Gregor9b3064b2009-04-01 22:41:11 +00009
Nick Lewyckyba5f6ec2010-04-24 01:30:46 +000010struct C1 {
Douglas Gregora3a83512009-04-01 23:51:29 +000011 virtual void f();
12 static void g();
13};
Douglas Gregor9b3064b2009-04-01 22:41:11 +000014struct C2 : virtual public virtual C1 { }; // expected-error{{duplicate}}
15
Douglas Gregora3a83512009-04-01 23:51:29 +000016virtual void C1::f() { } // expected-error{{'virtual' can only be specified inside the class definition}}
17
18static void C1::g() { } // expected-error{{'static' can only be specified inside the class definition}}
19
20template<int Value> struct CT { }; // expected-note{{previous use is here}}
Douglas Gregor9b3064b2009-04-01 22:41:11 +000021
22CT<10 >> 2> ct; // expected-warning{{require parentheses}}
Douglas Gregora3a83512009-04-01 23:51:29 +000023
24class C3 {
25public:
26 C3(C3, int i = 0); // expected-error{{copy constructor must pass its first argument by reference}}
27};
28
29struct CT<0> { }; // expected-error{{'template<>'}}
30
31template<> class CT<1> { }; // expected-error{{tag type}}
Anders Carlssonad26b732009-11-10 03:24:44 +000032
Douglas Gregor28485232010-02-01 23:46:27 +000033// Access declarations
34class A {
35protected:
36 int foo();
37};
Anders Carlssonad26b732009-11-10 03:24:44 +000038
Douglas Gregor28485232010-02-01 23:46:27 +000039class B : public A {
40 A::foo; // expected-warning{{access declarations are deprecated}}
41};
Douglas Gregor2eef8292010-03-24 07:14:45 +000042
43void f() throw();
44void f(); // expected-warning{{missing exception specification}}
Douglas Gregor1aae80b2010-04-14 20:27:54 +000045
46namespace rdar7853795 {
47 struct A {
48 bool getNumComponents() const; // expected-note{{declared here}}
Nick Lewyckyba5f6ec2010-04-24 01:30:46 +000049 void dump() const {
Douglas Gregor1aae80b2010-04-14 20:27:54 +000050 getNumComponenets(); // expected-error{{use of undeclared identifier 'getNumComponenets'; did you mean 'getNumComponents'?}}
51 }
52 };
53}
Douglas Gregorb1f6fa42010-09-07 14:35:10 +000054
55namespace 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 Greifa4a301d2010-09-08 00:31:13 +000063
Francois Pichetc71d8eb2010-10-01 21:19:28 +000064// extra qualification on member
65class C {
66 int C::foo();
67};
68
Argyrios Kyrtzidisa6eb5f82010-10-08 02:39:23 +000069namespace rdar8488464 {
70int x == 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}}
71
72void f() {
73 int x == 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}}
74 (void)x;
75 if (int x == 0) { // expected-error {{invalid '==' at end of declaration; did you mean '='?}}
76 (void)x;
77 }
78}
79}
80
Francois Pichet4147d302011-03-27 19:41:34 +000081template <class A>
82class F1 {
83public:
84 template <int B>
85 class Iterator {
86 };
87};
88
89template<class T>
90class F2 {
91 typename F1<T>:: /*template*/ Iterator<0> Mypos; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
92};
93
94template <class T>
95void f(){
96 typename F1<T>:: /*template*/ Iterator<0> Mypos; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
97}
98
Anna Zaks67221552011-07-28 19:51:27 +000099// Tests for &/* fixits radar 7113438.
100class AD {};
101class BD: public AD {};
102
103void test (BD &br) {
104 AD* aPtr;
105 BD b;
106 aPtr = b; // expected-error {{assigning to 'AD *' from incompatible type 'BD'; take the address with &}}
107 aPtr = br; // expected-error {{assigning to 'A *' from incompatible type 'B'; take the address with &}}
108}
109
Francois Pichet4147d302011-03-27 19:41:34 +0000110