fixit.cpp revision 0706df40064d4d7559b4304af79d519033414b84
1// RUN: cp %s %t
2// RUN: not %clang_cc1 -pedantic -Wall -fixit -x c++ %t
3// RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror -x c++ %t
4
5/* This is a test of the various code modification hints that are
6   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. */
9
10struct C1 {
11  virtual void f();
12  static void g();
13};
14struct C2 : virtual public virtual C1 { }; // expected-error{{duplicate}}
15
16virtual 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}}
21
22CT<10 >> 2> ct; // expected-warning{{require parentheses}}
23
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}}
32
33// Access declarations
34class A {
35protected:
36  int foo();
37};
38
39class B : public A {
40  A::foo; // expected-warning{{access declarations are deprecated}}
41};
42
43void f() throw();
44void f(); // expected-warning{{missing exception specification}}
45
46namespace rdar7853795 {
47  struct A {
48    bool getNumComponents() const; // expected-note{{declared here}}
49    void dump() const {
50      getNumComponenets(); // expected-error{{use of undeclared identifier 'getNumComponenets'; did you mean 'getNumComponents'?}}
51    }
52  };
53}
54
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}
63
64// extra qualification on member
65class C {
66  int C::foo();
67};
68
69namespace 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
81template <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
99// 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
110void foo1() const {} // expected-error {{type qualifier is not allowed on this function}}
111void foo2() volatile {} // expected-error {{type qualifier is not allowed on this function}}
112void foo3() const volatile {} // expected-error {{type qualifier is not allowed on this function}}
113
114struct S { void f(int, char); };
115int itsAComma,
116itsAComma2 = 0,
117oopsAComma(42), // expected-error {{expected ';' after declaration}}
118AD oopsMoreCommas() {
119  static int n = 0,
120  static char c,
121  &d = c, // expected-error {{expected ';' after declaration}}
122  S s, // expected-error {{expected ';' after declaration}}
123  s.f(n, d);
124  AD ad, // expected-error {{expected ';' after declaration}}
125  return ad;
126}
127