1 // RUN: %clang_cc1 -pedantic -Wall -Wno-comment -verify -fcxx-exceptions -x c++ %s
2 // RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -x c++ -std=c++11 %s 2>&1 | FileCheck %s
4 // RUN: not %clang_cc1 -pedantic -Wall -Wno-comment -fcxx-exceptions -fixit -x c++ %t
5 // RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror -Wno-comment -fcxx-exceptions -x c++ %t
7 /* This is a test of the various code modification hints that are
8 provided as part of warning or extension diagnostics. All of the
9 warnings will be fixed by -fixit, and the resulting file should
10 compile cleanly with -Werror -pedantic. */
16 struct C2
: virtual public virtual C1
{ }; // expected-error{{duplicate}}
18 virtual void C1::f() { } // expected-error{{'virtual' can only be specified inside the class definition}}
20 static void C1::g() { } // expected-error{{'static' can only be specified inside the class definition}}
22 template<int Value
> struct CT
{ template<typename
> struct Inner
; }; // expected-note{{previous use is here}}
24 CT
<10 >> 2> ct
; // expected-warning{{require parentheses}}
28 C3(C3
, int i
= 0); // expected-error{{copy constructor must pass its first argument by reference}}
31 struct CT
<0> { }; // expected-error{{'template<>'}}
33 template<> union CT
<1> { }; // expected-error{{tag type}}
35 struct CT
<2>::Inner
<int> { }; // expected-error 2{{'template<>'}}
37 // Access declarations
44 A::foo
; // expected-warning{{access declarations are deprecated}}
47 void f() throw(); // expected-note{{previous}}
48 void f(); // expected-warning{{missing exception specification}}
50 namespace rdar7853795
{
52 bool getNumComponents() const; // expected-note{{declared here}}
54 getNumComponenets(); // expected-error{{use of undeclared identifier 'getNumComponenets'; did you mean 'getNumComponents'?}}
59 namespace rdar7796492
{
60 struct A
{ int x
, y
; A(); };
63 : x(1) y(2) { // expected-error{{missing ',' between base or member initializers}}
68 // extra qualification on member
70 int C::foo(); // expected-error {{extra qualification}}
73 namespace rdar8488464
{
75 int x1
&= 0; // expected-error {{invalid '&=' at end of declaration; did you mean '='?}}
76 int x2
*= 0; // expected-error {{invalid '*=' at end of declaration; did you mean '='?}}
77 int x3
+= 0; // expected-error {{invalid '+=' at end of declaration; did you mean '='?}}
78 int x4
-= 0; // expected-error {{invalid '-=' at end of declaration; did you mean '='?}}
79 int x5
!= 0; // expected-error {{invalid '!=' at end of declaration; did you mean '='?}}
80 int x6
/= 0; // expected-error {{invalid '/=' at end of declaration; did you mean '='?}}
81 int x7
%= 0; // expected-error {{invalid '%=' at end of declaration; did you mean '='?}}
82 int x8
<= 0; // expected-error {{invalid '<=' at end of declaration; did you mean '='?}}
83 int x9
<<= 0; // expected-error {{invalid '<<=' at end of declaration; did you mean '='?}}
84 int x10
>= 0; // expected-error {{invalid '>=' at end of declaration; did you mean '='?}}
85 int x11
>>= 0; // expected-error {{invalid '>>=' at end of declaration; did you mean '='?}}
86 int x12
^= 0; // expected-error {{invalid '^=' at end of declaration; did you mean '='?}}
87 int x13
|= 0; // expected-error {{invalid '|=' at end of declaration; did you mean '='?}}
88 int x14
== 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}}
93 int x1
&= 0; // expected-error {{invalid '&=' at end of declaration; did you mean '='?}}
95 int x2
*= 0; // expected-error {{invalid '*=' at end of declaration; did you mean '='?}}
97 int x3
+= 0; // expected-error {{invalid '+=' at end of declaration; did you mean '='?}}
99 int x4
-= 0; // expected-error {{invalid '-=' at end of declaration; did you mean '='?}}
101 int x5
!= 0; // expected-error {{invalid '!=' at end of declaration; did you mean '='?}}
103 int x6
/= 0; // expected-error {{invalid '/=' at end of declaration; did you mean '='?}}
105 int x7
%= 0; // expected-error {{invalid '%=' at end of declaration; did you mean '='?}}
107 int x8
<= 0; // expected-error {{invalid '<=' at end of declaration; did you mean '='?}}
109 int x9
<<= 0; // expected-error {{invalid '<<=' at end of declaration; did you mean '='?}}
111 int x10
>= 0; // expected-error {{invalid '>=' at end of declaration; did you mean '='?}}
113 int x11
>>= 0; // expected-error {{invalid '>>=' at end of declaration; did you mean '='?}}
115 int x12
^= 0; // expected-error {{invalid '^=' at end of declaration; did you mean '='?}}
117 int x13
|= 0; // expected-error {{invalid '|=' at end of declaration; did you mean '='?}}
119 int x14
== 0; // expected-error {{invalid '==' at end of declaration; did you mean '='?}}
121 if (int x
= 0) { (void)x
; }
122 if (int x1
&= 0) { (void)x1
; } // expected-error {{invalid '&=' at end of declaration; did you mean '='?}}
123 if (int x2
*= 0) { (void)x2
; } // expected-error {{invalid '*=' at end of declaration; did you mean '='?}}
124 if (int x3
+= 0) { (void)x3
; } // expected-error {{invalid '+=' at end of declaration; did you mean '='?}}
125 if (int x4
-= 0) { (void)x4
; } // expected-error {{invalid '-=' at end of declaration; did you mean '='?}}
126 if (int x5
!= 0) { (void)x5
; } // expected-error {{invalid '!=' at end of declaration; did you mean '='?}}
127 if (int x6
/= 0) { (void)x6
; } // expected-error {{invalid '/=' at end of declaration; did you mean '='?}}
128 if (int x7
%= 0) { (void)x7
; } // expected-error {{invalid '%=' at end of declaration; did you mean '='?}}
129 if (int x8
<= 0) { (void)x8
; } // expected-error {{invalid '<=' at end of declaration; did you mean '='?}}
130 if (int x9
<<= 0) { (void)x9
; } // expected-error {{invalid '<<=' at end of declaration; did you mean '='?}}
131 if (int x10
>= 0) { (void)x10
; } // expected-error {{invalid '>=' at end of declaration; did you mean '='?}}
132 if (int x11
>>= 0) { (void)x11
; } // expected-error {{invalid '>>=' at end of declaration; did you mean '='?}}
133 if (int x12
^= 0) { (void)x12
; } // expected-error {{invalid '^=' at end of declaration; did you mean '='?}}
134 if (int x13
|= 0) { (void)x13
; } // expected-error {{invalid '|=' at end of declaration; did you mean '='?}}
135 if (int x14
== 0) { (void)x14
; } // expected-error {{invalid '==' at end of declaration; did you mean '='?}}
149 typename F1
<T
>:: /*template*/ Iterator
<0> Mypos
; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
154 typename F1
<T
>:: /*template*/ Iterator
<0> Mypos
; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
157 // Tests for &/* fixits radar 7113438.
159 class BD
: public AD
{};
164 aPtr
= b
; // expected-error {{assigning to 'AD *' from incompatible type 'BD'; take the address with &}}
165 aPtr
= br
; // expected-error {{assigning to 'AD *' from incompatible type 'BD'; take the address with &}}
168 void foo1() const {} // expected-error {{non-member function cannot have 'const' qualifier}}
169 void foo2() volatile {} // expected-error {{non-member function cannot have 'volatile' qualifier}}
170 void foo3() const volatile {} // expected-error {{non-member function cannot have 'const volatile' qualifier}}
172 struct S
{ void f(int, char); };
175 oopsAComma(42), // expected-error {{expected ';' at end of declaration}}
176 AD
oopsMoreCommas() {
177 static int n
= 0, // expected-error {{expected ';' at end of declaration}}
179 &d
= c
, // expected-error {{expected ';' at end of declaration}}
180 S s
, // expected-error {{expected ';' at end of declaration}}
182 AD ad
, // expected-error {{expected ';' at end of declaration}}
185 struct MoreAccidentalCommas
{
188 : 4, // expected-error {{expected ';' at end of declaration}}
189 char c
, // expected-error {{expected ';' at end of declaration}}
190 double d
, // expected-error {{expected ';' at end of declaration}}
191 MoreAccidentalCommas
*next
, // expected-error {{expected ';' at end of declaration}}
193 int k
, // expected-error {{expected ';' at end of declaration}}
194 friend void f(MoreAccidentalCommas
) {}
195 int k2
, // expected-error {{expected ';' at end of declaration}}
196 virtual void g(), // expected-error {{expected ';' at end of declaration}}
199 template<class T
> struct Mystery
;
200 template<class T
> typedef Mystery
<T
>::type
getMysteriousThing() { // \
201 expected
-error
{{function definition declared
'typedef'}} \
202 expected
-error
{{missing
'typename' prior to dependent
}}
203 return Mystery
<T
>::get();
206 template<template<typename
> Foo
, // expected-error {{template template parameter requires 'class' after the parameter list}}
207 template<typename
> typename Bar
, // expected-warning {{template template parameter using 'typename' is a C++1z extension}}
208 template<typename
> struct Baz
> // expected-error {{template template parameter requires 'class' after the parameter list}}
211 namespace ShadowedTagType
{
215 void SetBar(Bar bar
);
216 Bar
Bar(); // expected-note 2 {{enum 'Bar' is hidden by a non-type declaration of 'Bar' here}}
218 Bar bar_
; // expected-error {{must use 'enum' tag to refer to type 'Bar' in this scope}}
220 void Foo::SetBar(Bar bar
) { bar_
= bar
; } // expected-error {{must use 'enum' tag to refer to type 'Bar' in this scope}}
224 char c
= NULL
; // expected-warning {{implicit conversion of NULL constant to 'char'}}
225 double dbl
= NULL
; // expected-warning {{implicit conversion of NULL constant to 'double'}}
227 namespace arrow_suggest
{
229 template <typename T
>
232 wrapped_ptr(T
* ptr
) : ptr_(ptr
) {}
233 T
* operator->() { return ptr_
; }
244 wrapped_ptr
<Worker
> worker(new Worker
);
245 worker
.DoSomething(); // expected-error {{no member named 'DoSomething' in 'arrow_suggest::wrapped_ptr<arrow_suggest::Worker>'; did you mean to use '->' instead of '.'?}}
248 } // namespace arrow_suggest
250 // Make sure fixing namespace-qualified identifiers functions properly with
251 // namespace-aware typo correction/
252 namespace redecl_typo
{
254 void BeEvil(); // expected-note {{'BeEvil' declared here}}
258 bool isGood(); // expected-note {{'Bar::Foo::isGood' declared here}}
262 bool Foo::isGood() { // expected-error {{out-of-line definition of 'isGood' does not match any declaration in namespace 'redecl_typo::Foo'; did you mean 'Bar::Foo::isGood'?}}
265 void Foo::beEvil() {} // expected-error {{out-of-line definition of 'beEvil' does not match any declaration in namespace 'redecl_typo::Foo'; did you mean 'BeEvil'?}}
268 // Test behavior when a template-id is ended by a token which starts with '>'.
269 namespace greatergreater
{
270 template<typename T
> struct S
{ S(); S(T
); };
271 void f(S
<int>=0); // expected-error {{a space is required between a right angle bracket and an equals sign (use '> =')}}
273 // FIXME: The fix-its here overlap so -fixit mode can't apply the second one.
274 //void f(S<S<int>>=S<int>());
277 template<typename T
> Shr(T
);
278 template<typename T
> void operator >>=(T
);
281 template<template<typename
>> struct TemplateTemplateParam
; // expected-error {{requires 'class'}}
283 template<typename T
> void t();
285 void (*p
)() = &t
<int>;
286 (void)(&t
<int>==p
); // expected-error {{use '> ='}}
287 (void)(&t
<int>>=p
); // expected-error {{use '> >'}}
288 (void)(&t
<S
<int>>>=p
); // expected-error {{use '> >'}}
289 (Shr
)&t
<S
<int>>>>=p
; // expected-error {{use '> >'}}
291 // FIXME: We correct this to '&t<int> > >= p;' not '&t<int> >>= p;'
294 // FIXME: The fix-its here overlap.
295 //(void)(&t<S<int>>==p);
301 (void)&i
; // expected-error{{must explicitly qualify name of member function when taking its address}}
306 namespace dtor_fixit
{
308 ~bar() { } // expected-error {{expected the class name after '~' to name a destructor}}
309 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:6-[[@LINE-1]]:9}:"foo"
315 ~bar::bar() {} // expected-error {{'~' in destructor name should be after nested name specifier}}
316 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:4}:""
317 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:9-[[@LINE-2]]:9}:"~"
321 template<typename T
> struct X
{};
322 X
<int *p
> x
; // expected-error {{type-id cannot have a name}}
330 const char* foo(A
&x
)
332 return x
.str
.(); // expected-error {{unexpected '.' in function call; perhaps remove the '.'?}}
334 bool bar(A x
, const char *y
) {
335 return foo
->(x
) == y
; // expected-error {{unexpected '->' in function call; perhaps remove the '->'?}}
347 return c
->a
; // expected-error {{member reference type 'PR15045::Cl0' is not a pointer; maybe you meant to use '.'?}}
351 namespace curly_after_base_clause
{
352 struct A
{ void f(); };
353 struct B
: A
// expected-error{{expected '{' after base class list}}
354 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:" {"
357 struct C
: A
// expected-error{{expected '{' after base class list}}
358 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:" {"
361 struct D
: A
// expected-error{{expected '{' after base class list}}
362 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:" {"
365 struct E
: A
// expected-error{{expected '{' after base class list}}
366 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:" {"
367 template<typename T
> struct inner
{ };
369 struct F
: A
// expected-error{{expected '{' after base class list}}
370 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:" {"
373 #if __cplusplus >= 201103L
374 struct G
: A
// expected-error{{expected '{' after base class list}}
375 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:" {"
378 struct H
: A
// expected-error{{expected '{' after base class list}}
379 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:13}:" {"
380 static_assert(true, "");
385 struct conversion_operator
{
386 conversion_operator::* const operator int(); // expected-error {{put the complete type after 'operator'}}
387 // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:32}:""
388 // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:44-[[@LINE-2]]:44}:" conversion_operator::* const"