fixit.cpp revision 6e1fd33116c2977174f2df17ac8bad2a32659db8
1// RUN: %clang_cc1 -pedantic -Wall -Wno-comment -verify -fcxx-exceptions -x c++ %s
2// RUN: cp %s %t
3// 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
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
11struct C1 {
12  virtual void f();
13  static void g();
14};
15struct C2 : virtual public virtual C1 { }; // expected-error{{duplicate}}
16
17virtual 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}}
22
23CT<10 >> 2> ct; // expected-warning{{require parentheses}}
24
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
32template<> union CT<1> { }; // expected-error{{tag type}}
33
34// Access declarations
35class A {
36protected:
37  int foo();
38};
39
40class B : public A {
41  A::foo; // expected-warning{{access declarations are deprecated}}
42};
43
44void f() throw(); // expected-note{{previous}}
45void f(); // expected-warning{{missing exception specification}}
46
47namespace 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
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}
64
65// extra qualification on member
66class C {
67  int C::foo(); // expected-warning {{extra qualification}}
68};
69
70namespace 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
82template <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
100// 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 &}}
108  aPtr = br; // expected-error {{assigning to 'AD *' from incompatible type 'BD'; take the address with &}}
109}
110
111void 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}}
114
115struct S { void f(int, char); };
116int itsAComma,
117itsAComma2 = 0,
118oopsAComma(42), // expected-error {{expected ';' at end of declaration}}
119AD 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
129int extraSemi1(); // expected-error {{stray ';' in function definition}}
130{
131  return 0;
132}
133
134int extraSemi2(); // expected-error {{stray ';' in function definition}}
135try {
136} catch (...) {
137}
138
139template<class T> struct Mystery;
140template<class T> typedef Mystery<T>::type getMysteriousThing() { // \
141  expected-error {{function definition declared 'typedef'}} \
142  expected-error {{missing 'typename' prior to dependent}}
143  return Mystery<T>::get();
144}
145