fixit.cpp revision 460ef136eb96b879f149c8703938a13c35b4bc68
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; 72int x1 &= 0; // expected-error {{invalid '&=' at end of declaration; did you mean '='?}} 73int x2 *= 0; // expected-error {{invalid '*=' at end of declaration; did you mean '='?}} 74int x3 += 0; // expected-error {{invalid '+=' at end of declaration; did you mean '='?}} 75int x4 -= 0; // expected-error {{invalid '-=' at end of declaration; did you mean '='?}} 76int x5 != 0; // expected-error {{invalid '!=' at end of declaration; did you mean '='?}} 77int x6 /= 0; // expected-error {{invalid '/=' at end of declaration; did you mean '='?}} 78int x7 %= 0; // expected-error {{invalid '%=' at end of declaration; did you mean '='?}} 79int x8 <= 0; // expected-error {{invalid '<=' at end of declaration; did you mean '='?}} 80int x9 <<= 0; // expected-error {{invalid '<<=' at end of declaration; did you mean '='?}} 81int x10 >= 0; // expected-error {{invalid '>=' at end of declaration; did you mean '='?}} 82int x11 >>= 0; // expected-error {{invalid '>>=' at end of declaration; did you mean '='?}} 83int x12 ^= 0; // expected-error {{invalid '^=' at end of declaration; did you mean '='?}} 84int x13 |= 0; // expected-error {{invalid '|=' at end of declaration; did you mean '='?}} 85int x14 == 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}} 86 87void f() { 88 int x = 0; 89 (void)x; 90 int x1 &= 0; // expected-error {{invalid '&=' at end of declaration; did you mean '='?}} 91 (void)x1; 92 int x2 *= 0; // expected-error {{invalid '*=' at end of declaration; did you mean '='?}} 93 (void)x2; 94 int x3 += 0; // expected-error {{invalid '+=' at end of declaration; did you mean '='?}} 95 (void)x3; 96 int x4 -= 0; // expected-error {{invalid '-=' at end of declaration; did you mean '='?}} 97 (void)x4; 98 int x5 != 0; // expected-error {{invalid '!=' at end of declaration; did you mean '='?}} 99 (void)x5; 100 int x6 /= 0; // expected-error {{invalid '/=' at end of declaration; did you mean '='?}} 101 (void)x6; 102 int x7 %= 0; // expected-error {{invalid '%=' at end of declaration; did you mean '='?}} 103 (void)x7; 104 int x8 <= 0; // expected-error {{invalid '<=' at end of declaration; did you mean '='?}} 105 (void)x8; 106 int x9 <<= 0; // expected-error {{invalid '<<=' at end of declaration; did you mean '='?}} 107 (void)x9; 108 int x10 >= 0; // expected-error {{invalid '>=' at end of declaration; did you mean '='?}} 109 (void)x10; 110 int x11 >>= 0; // expected-error {{invalid '>>=' at end of declaration; did you mean '='?}} 111 (void)x11; 112 int x12 ^= 0; // expected-error {{invalid '^=' at end of declaration; did you mean '='?}} 113 (void)x12; 114 int x13 |= 0; // expected-error {{invalid '|=' at end of declaration; did you mean '='?}} 115 (void)x13; 116 int x14 == 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}} 117 (void)x14; 118 if (int x = 0) { (void)x; } 119 if (int x1 &= 0) { (void)x1; } // expected-error {{invalid '&=' at end of declaration; did you mean '='?}} 120 if (int x2 *= 0) { (void)x2; } // expected-error {{invalid '*=' at end of declaration; did you mean '='?}} 121 if (int x3 += 0) { (void)x3; } // expected-error {{invalid '+=' at end of declaration; did you mean '='?}} 122 if (int x4 -= 0) { (void)x4; } // expected-error {{invalid '-=' at end of declaration; did you mean '='?}} 123 if (int x5 != 0) { (void)x5; } // expected-error {{invalid '!=' at end of declaration; did you mean '='?}} 124 if (int x6 /= 0) { (void)x6; } // expected-error {{invalid '/=' at end of declaration; did you mean '='?}} 125 if (int x7 %= 0) { (void)x7; } // expected-error {{invalid '%=' at end of declaration; did you mean '='?}} 126 if (int x8 <= 0) { (void)x8; } // expected-error {{invalid '<=' at end of declaration; did you mean '='?}} 127 if (int x9 <<= 0) { (void)x9; } // expected-error {{invalid '<<=' at end of declaration; did you mean '='?}} 128 if (int x10 >= 0) { (void)x10; } // expected-error {{invalid '>=' at end of declaration; did you mean '='?}} 129 if (int x11 >>= 0) { (void)x11; } // expected-error {{invalid '>>=' at end of declaration; did you mean '='?}} 130 if (int x12 ^= 0) { (void)x12; } // expected-error {{invalid '^=' at end of declaration; did you mean '='?}} 131 if (int x13 |= 0) { (void)x13; } // expected-error {{invalid '|=' at end of declaration; did you mean '='?}} 132 if (int x14 == 0) { (void)x14; } // expected-error {{invalid '==' at end of declaration; did you mean '='?}} 133} 134} 135 136template <class A> 137class F1 { 138public: 139 template <int B> 140 class Iterator { 141 }; 142}; 143 144template<class T> 145class F2 { 146 typename F1<T>:: /*template*/ Iterator<0> Mypos; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}} 147}; 148 149template <class T> 150void f(){ 151 typename F1<T>:: /*template*/ Iterator<0> Mypos; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}} 152} 153 154// Tests for &/* fixits radar 7113438. 155class AD {}; 156class BD: public AD {}; 157 158void test (BD &br) { 159 AD* aPtr; 160 BD b; 161 aPtr = b; // expected-error {{assigning to 'AD *' from incompatible type 'BD'; take the address with &}} 162 aPtr = br; // expected-error {{assigning to 'AD *' from incompatible type 'BD'; take the address with &}} 163} 164 165void foo1() const {} // expected-error {{non-member function cannot have 'const' qualifier}} 166void foo2() volatile {} // expected-error {{non-member function cannot have 'volatile' qualifier}} 167void foo3() const volatile {} // expected-error {{non-member function cannot have 'const volatile' qualifier}} 168 169struct S { void f(int, char); }; 170int itsAComma, 171itsAComma2 = 0, 172oopsAComma(42), // expected-error {{expected ';' at end of declaration}} 173AD oopsMoreCommas() { 174 static int n = 0, // expected-error {{expected ';' at end of declaration}} 175 static char c, 176 &d = c, // expected-error {{expected ';' at end of declaration}} 177 S s, // expected-error {{expected ';' at end of declaration}} 178 s.f(n, d); 179 AD ad, // expected-error {{expected ';' at end of declaration}} 180 return ad; 181} 182struct MoreAccidentalCommas { 183 int a : 5, 184 b : 7, 185 : 4, // expected-error {{expected ';' at end of declaration}} 186 char c, // expected-error {{expected ';' at end of declaration}} 187 double d, // expected-error {{expected ';' at end of declaration}} 188 MoreAccidentalCommas *next, // expected-error {{expected ';' at end of declaration}} 189public: 190 int k, // expected-error {{expected ';' at end of declaration}} 191 friend void f(MoreAccidentalCommas) {} 192 int k2, // expected-error {{expected ';' at end of declaration}} 193 virtual void g(), // expected-error {{expected ';' at end of declaration}} 194}; 195 196template<class T> struct Mystery; 197template<class T> typedef Mystery<T>::type getMysteriousThing() { // \ 198 expected-error {{function definition declared 'typedef'}} \ 199 expected-error {{missing 'typename' prior to dependent}} 200 return Mystery<T>::get(); 201} 202 203template<template<typename> Foo, // expected-error {{expected 'class' before 'Foo'}} 204 template<typename> typename Bar, // expected-error {{expected 'class' instead of 'typename'}} 205 template<typename> struct Baz> // expected-error {{expected 'class' instead of 'struct'}} 206void func(); 207