1 // RUN: %clang_cc1 -pedantic -Wall -verify -fcxx-exceptions -x c++ %s
2 // RUN: cp %s %t
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
5 
6 /* This is a test of the various code modification hints that are
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. */
10 
11 struct C1 {
12   virtual void f();
13   static void g();
14 };
15 struct C2 : virtual public virtual C1 { }; // expected-error{{duplicate}}
16 
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}}
22 
23 CT<10 >> 2> ct; // expected-warning{{require parentheses}}
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 
32 template<> union CT<1> { }; // expected-error{{tag type}}
33 
34 // Access declarations
35 class A {
36 protected:
37   int foo();
38 };
39 
40 class B : public A {
41   A::foo; // expected-warning{{access declarations are deprecated}}
42 };
43 
44 void f() throw(); // expected-note{{previous}}
45 void f(); // expected-warning{{missing exception specification}}
46 
47 namespace rdar7853795 {
48   struct A {
49     bool getNumComponents() const; // expected-note{{declared here}}
50     void dump() const {
51       getNumComponenets(); // expected-error{{use of undeclared identifier 'getNumComponenets'; did you mean 'getNumComponents'?}}
52     }
53   };
54 }
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 }
64 
65 // extra qualification on member
66 class C {
67   int C::foo(); // expected-warning {{extra qualification}}
68 };
69 
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 
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 
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 &}}
108   aPtr = br; // expected-error {{assigning to 'AD *' from incompatible type 'BD'; take the address with &}}
109 }
110 
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}}
114 
115 struct S { void f(int, char); };
116 int itsAComma,
117 itsAComma2 = 0,
118 oopsAComma(42), // expected-error {{expected ';' at end of declaration}}
119 AD oopsMoreCommas() {
120   static int n = 0, // expected-error {{expected ';' at end of declaration}}
121   static char c,
122   &d = c, // expected-error {{expected ';' at end of declaration}}
123   S s, // expected-error {{expected ';' at end of declaration}}
124   s.f(n, d);
125   AD ad, // expected-error {{expected ';' at end of declaration}}
126   return ad;
127 }
128