2011-11-29 17:09:06 +08:00
// RUN: %clang_cc1 -pedantic -Wall -Wno-comment -verify -fcxx-exceptions -x c++ %s
2013-07-05 00:16:58 +08:00
// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits -x c++ %s 2>&1 | FileCheck %s
2010-04-24 09:30:46 +08:00
// RUN: cp %s %t
2011-11-29 17:09:06 +08:00
// RUN: not %clang_cc1 -pedantic -Wall -Wno-comment -fcxx-exceptions -fixit -x c++ %t
// RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror -Wno-comment -fcxx-exceptions -x c++ %t
2009-04-02 06:41:11 +08:00
/* This is a test of the various code modification hints that are
2009-04-02 11:20:30 +08:00
provided as part of warning or extension diagnostics . All of the
warnings will be fixed by - fixit , and the resulting file should
compile cleanly with - Werror - pedantic . */
2009-04-02 06:41:11 +08:00
2010-04-24 09:30:46 +08:00
struct C1 {
2009-04-02 07:51:29 +08:00
virtual void f ( ) ;
static void g ( ) ;
} ;
2009-04-02 06:41:11 +08:00
struct C2 : virtual public virtual C1 { } ; // expected-error{{duplicate}}
2009-04-02 07:51:29 +08:00
virtual void C1 : : f ( ) { } // expected-error{{'virtual' can only be specified inside the class definition}}
static void C1 : : g ( ) { } // expected-error{{'static' can only be specified inside the class definition}}
2014-04-17 11:29:33 +08:00
template < int Value > struct CT { template < typename > struct Inner ; } ; // expected-note{{previous use is here}}
2009-04-02 06:41:11 +08:00
CT < 10 > > 2 > ct ; // expected-warning{{require parentheses}}
2009-04-02 07:51:29 +08:00
class C3 {
public :
C3 ( C3 , int i = 0 ) ; // expected-error{{copy constructor must pass its first argument by reference}}
} ;
struct CT < 0 > { } ; // expected-error{{'template<>'}}
2011-10-20 09:41:28 +08:00
template < > union CT < 1 > { } ; // expected-error{{tag type}}
2009-11-10 11:24:44 +08:00
2014-04-17 11:29:33 +08:00
struct CT < 2 > : : Inner < int > { } ; // expected-error 2{{'template<>'}}
2010-02-02 07:46:27 +08:00
// Access declarations
class A {
protected :
int foo ( ) ;
} ;
2009-11-10 11:24:44 +08:00
2010-02-02 07:46:27 +08:00
class B : public A {
A : : foo ; // expected-warning{{access declarations are deprecated}}
} ;
2010-03-24 15:14:45 +08:00
2011-10-20 09:41:28 +08:00
void f ( ) throw ( ) ; // expected-note{{previous}}
2010-03-24 15:14:45 +08:00
void f ( ) ; // expected-warning{{missing exception specification}}
2010-04-15 04:27:54 +08:00
namespace rdar7853795 {
struct A {
bool getNumComponents ( ) const ; // expected-note{{declared here}}
2010-04-24 09:30:46 +08:00
void dump ( ) const {
2010-04-15 04:27:54 +08:00
getNumComponenets ( ) ; // expected-error{{use of undeclared identifier 'getNumComponenets'; did you mean 'getNumComponents'?}}
}
} ;
}
2010-09-07 22:35:10 +08:00
namespace rdar7796492 {
2012-06-12 00:06:57 +08:00
struct A { int x , y ; A ( ) ; } ;
2010-09-07 22:35:10 +08:00
A : : A ( )
: x ( 1 ) y ( 2 ) { // expected-error{{missing ',' between base or member initializers}}
}
}
2010-09-08 08:31:13 +08:00
2010-10-02 05:19:28 +08:00
// extra qualification on member
class C {
2012-09-14 04:16:20 +08:00
int C : : foo ( ) ; // expected-error {{extra qualification}}
2010-10-02 05:19:28 +08:00
} ;
2010-10-08 10:39:23 +08:00
namespace rdar8488464 {
Extend the error of invalid token after declarations to include fixits for
!=, %=, ^=, &=, *=, -=, |=, /=, <<=, <=, >=, and >>= to =.
llvm-svn: 148499
2012-01-20 06:01:51 +08:00
int x = 0 ;
int x1 & = 0 ; // expected-error {{invalid '&=' at end of declaration; did you mean '='?}}
int x2 * = 0 ; // expected-error {{invalid '*=' at end of declaration; did you mean '='?}}
int x3 + = 0 ; // expected-error {{invalid '+=' at end of declaration; did you mean '='?}}
int x4 - = 0 ; // expected-error {{invalid '-=' at end of declaration; did you mean '='?}}
int x5 ! = 0 ; // expected-error {{invalid '!=' at end of declaration; did you mean '='?}}
int x6 / = 0 ; // expected-error {{invalid '/=' at end of declaration; did you mean '='?}}
int x7 % = 0 ; // expected-error {{invalid '%=' at end of declaration; did you mean '='?}}
int x8 < = 0 ; // expected-error {{invalid '<=' at end of declaration; did you mean '='?}}
int x9 < < = 0 ; // expected-error {{invalid '<<=' at end of declaration; did you mean '='?}}
int x10 > = 0 ; // expected-error {{invalid '>=' at end of declaration; did you mean '='?}}
int x11 > > = 0 ; // expected-error {{invalid '>>=' at end of declaration; did you mean '='?}}
int x12 ^ = 0 ; // expected-error {{invalid '^=' at end of declaration; did you mean '='?}}
int x13 | = 0 ; // expected-error {{invalid '|=' at end of declaration; did you mean '='?}}
int x14 = = 0 ; // expected-error {{invalid '==' at end of declaration; did you mean '='?}}
2010-10-08 10:39:23 +08:00
void f ( ) {
Extend the error of invalid token after declarations to include fixits for
!=, %=, ^=, &=, *=, -=, |=, /=, <<=, <=, >=, and >>= to =.
llvm-svn: 148499
2012-01-20 06:01:51 +08:00
int x = 0 ;
2010-10-08 10:39:23 +08:00
( void ) x ;
Extend the error of invalid token after declarations to include fixits for
!=, %=, ^=, &=, *=, -=, |=, /=, <<=, <=, >=, and >>= to =.
llvm-svn: 148499
2012-01-20 06:01:51 +08:00
int x1 & = 0 ; // expected-error {{invalid '&=' at end of declaration; did you mean '='?}}
( void ) x1 ;
int x2 * = 0 ; // expected-error {{invalid '*=' at end of declaration; did you mean '='?}}
( void ) x2 ;
int x3 + = 0 ; // expected-error {{invalid '+=' at end of declaration; did you mean '='?}}
( void ) x3 ;
int x4 - = 0 ; // expected-error {{invalid '-=' at end of declaration; did you mean '='?}}
( void ) x4 ;
int x5 ! = 0 ; // expected-error {{invalid '!=' at end of declaration; did you mean '='?}}
( void ) x5 ;
int x6 / = 0 ; // expected-error {{invalid '/=' at end of declaration; did you mean '='?}}
( void ) x6 ;
int x7 % = 0 ; // expected-error {{invalid '%=' at end of declaration; did you mean '='?}}
( void ) x7 ;
int x8 < = 0 ; // expected-error {{invalid '<=' at end of declaration; did you mean '='?}}
( void ) x8 ;
int x9 < < = 0 ; // expected-error {{invalid '<<=' at end of declaration; did you mean '='?}}
( void ) x9 ;
int x10 > = 0 ; // expected-error {{invalid '>=' at end of declaration; did you mean '='?}}
( void ) x10 ;
int x11 > > = 0 ; // expected-error {{invalid '>>=' at end of declaration; did you mean '='?}}
( void ) x11 ;
int x12 ^ = 0 ; // expected-error {{invalid '^=' at end of declaration; did you mean '='?}}
( void ) x12 ;
int x13 | = 0 ; // expected-error {{invalid '|=' at end of declaration; did you mean '='?}}
( void ) x13 ;
int x14 = = 0 ; // expected-error {{invalid '==' at end of declaration; did you mean '='?}}
( void ) x14 ;
if ( int x = 0 ) { ( void ) x ; }
if ( int x1 & = 0 ) { ( void ) x1 ; } // expected-error {{invalid '&=' at end of declaration; did you mean '='?}}
if ( int x2 * = 0 ) { ( void ) x2 ; } // expected-error {{invalid '*=' at end of declaration; did you mean '='?}}
if ( int x3 + = 0 ) { ( void ) x3 ; } // expected-error {{invalid '+=' at end of declaration; did you mean '='?}}
if ( int x4 - = 0 ) { ( void ) x4 ; } // expected-error {{invalid '-=' at end of declaration; did you mean '='?}}
if ( int x5 ! = 0 ) { ( void ) x5 ; } // expected-error {{invalid '!=' at end of declaration; did you mean '='?}}
if ( int x6 / = 0 ) { ( void ) x6 ; } // expected-error {{invalid '/=' at end of declaration; did you mean '='?}}
if ( int x7 % = 0 ) { ( void ) x7 ; } // expected-error {{invalid '%=' at end of declaration; did you mean '='?}}
if ( int x8 < = 0 ) { ( void ) x8 ; } // expected-error {{invalid '<=' at end of declaration; did you mean '='?}}
if ( int x9 < < = 0 ) { ( void ) x9 ; } // expected-error {{invalid '<<=' at end of declaration; did you mean '='?}}
if ( int x10 > = 0 ) { ( void ) x10 ; } // expected-error {{invalid '>=' at end of declaration; did you mean '='?}}
if ( int x11 > > = 0 ) { ( void ) x11 ; } // expected-error {{invalid '>>=' at end of declaration; did you mean '='?}}
if ( int x12 ^ = 0 ) { ( void ) x12 ; } // expected-error {{invalid '^=' at end of declaration; did you mean '='?}}
if ( int x13 | = 0 ) { ( void ) x13 ; } // expected-error {{invalid '|=' at end of declaration; did you mean '='?}}
if ( int x14 = = 0 ) { ( void ) x14 ; } // expected-error {{invalid '==' at end of declaration; did you mean '='?}}
2010-10-08 10:39:23 +08:00
}
}
2011-03-28 03:41:34 +08:00
template < class A >
class F1 {
public :
template < int B >
class Iterator {
} ;
} ;
template < class T >
class F2 {
typename F1 < T > : : /*template*/ Iterator < 0 > Mypos ; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
} ;
template < class T >
void f ( ) {
typename F1 < T > : : /*template*/ Iterator < 0 > Mypos ; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
}
2011-07-29 03:51:27 +08:00
// Tests for &/* fixits radar 7113438.
class AD { } ;
class BD : public AD { } ;
void test ( BD & br ) {
AD * aPtr ;
BD b ;
aPtr = b ; // expected-error {{assigning to 'AD *' from incompatible type 'BD'; take the address with &}}
2011-10-20 09:41:28 +08:00
aPtr = br ; // expected-error {{assigning to 'AD *' from incompatible type 'BD'; take the address with &}}
2011-07-29 03:51:27 +08:00
}
2012-02-10 19:05:11 +08:00
void foo1 ( ) const { } // expected-error {{non-member function cannot have 'const' qualifier}}
void foo2 ( ) volatile { } // expected-error {{non-member function cannot have 'volatile' qualifier}}
void foo3 ( ) const volatile { } // expected-error {{non-member function cannot have 'const volatile' qualifier}}
2011-03-28 03:41:34 +08:00
2011-10-20 05:33:05 +08:00
struct S { void f ( int , char ) ; } ;
int itsAComma ,
itsAComma2 = 0 ,
2011-10-20 09:41:28 +08:00
oopsAComma ( 42 ) , // expected-error {{expected ';' at end of declaration}}
2011-10-20 05:33:05 +08:00
AD oopsMoreCommas ( ) {
2011-10-20 09:41:28 +08:00
static int n = 0 , // expected-error {{expected ';' at end of declaration}}
2011-10-20 05:33:05 +08:00
static char c ,
2011-10-20 09:41:28 +08:00
& d = c , // expected-error {{expected ';' at end of declaration}}
S s , // expected-error {{expected ';' at end of declaration}}
2011-10-20 05:33:05 +08:00
s . f ( n , d ) ;
2011-10-20 09:41:28 +08:00
AD ad , // expected-error {{expected ';' at end of declaration}}
2011-10-20 05:33:05 +08:00
return ad ;
}
2012-01-10 06:31:44 +08:00
struct MoreAccidentalCommas {
int a : 5 ,
b : 7 ,
: 4 , // expected-error {{expected ';' at end of declaration}}
char c , // expected-error {{expected ';' at end of declaration}}
double d , // expected-error {{expected ';' at end of declaration}}
MoreAccidentalCommas * next , // expected-error {{expected ';' at end of declaration}}
public :
int k , // expected-error {{expected ';' at end of declaration}}
friend void f ( MoreAccidentalCommas ) { }
int k2 , // expected-error {{expected ';' at end of declaration}}
virtual void g ( ) , / / expected - error { { expected ' ; ' at end of declaration } }
} ;
2011-11-29 13:27:40 +08:00
2011-11-29 17:09:06 +08:00
template < class T > struct Mystery ;
template < class T > typedef Mystery < T > : : type getMysteriousThing ( ) { / / \
expected - error { { function definition declared ' typedef ' } } \
expected - error { { missing ' typename ' prior to dependent } }
return Mystery < T > : : get ( ) ;
}
2012-04-03 03:15:28 +08:00
2012-04-06 14:28:32 +08:00
template < template < typename > Foo , // expected-error {{template template parameter requires 'class' after the parameter list}}
2014-06-16 23:51:22 +08:00
template < typename > typename Bar , // expected-warning {{template template parameter using 'typename' is a C++1z extension}}
2012-04-06 14:28:32 +08:00
template < typename > struct Baz > // expected-error {{template template parameter requires 'class' after the parameter list}}
2012-04-03 03:15:28 +08:00
void func ( ) ;
2012-04-20 07:17:45 +08:00
namespace ShadowedTagType {
class Foo {
public :
enum Bar { X , Y } ;
void SetBar ( Bar bar ) ;
2012-04-28 02:26:49 +08:00
Bar Bar ( ) ; // expected-note 2 {{enum 'Bar' is hidden by a non-type declaration of 'Bar' here}}
2012-04-20 07:17:45 +08:00
private :
Bar bar_ ; // expected-error {{must use 'enum' tag to refer to type 'Bar' in this scope}}
} ;
void Foo : : SetBar ( Bar bar ) { bar_ = bar ; } // expected-error {{must use 'enum' tag to refer to type 'Bar' in this scope}}
2012-04-20 07:26:12 +08:00
}
2012-04-26 03:49:54 +08:00
2012-05-01 02:27:22 +08:00
# define NULL __null
char c = NULL ; // expected-warning {{implicit conversion of NULL constant to 'char'}}
2012-06-20 05:19:06 +08:00
double dbl = NULL ; // expected-warning {{implicit conversion of NULL constant to 'double'}}
2012-05-01 02:27:22 +08:00
2012-04-26 03:49:54 +08:00
namespace arrow_suggest {
template < typename T >
class wrapped_ptr {
public :
wrapped_ptr ( T * ptr ) : ptr_ ( ptr ) { }
T * operator - > ( ) { return ptr_ ; }
private :
T * ptr_ ;
} ;
class Worker {
public :
void DoSomething ( ) ;
} ;
void test ( ) {
wrapped_ptr < Worker > worker ( new Worker ) ;
worker . DoSomething ( ) ; // expected-error {{no member named 'DoSomething' in 'arrow_suggest::wrapped_ptr<arrow_suggest::Worker>'; did you mean to use '->' instead of '.'?}}
}
} // namespace arrow_suggest
2012-06-08 07:57:12 +08:00
// Make sure fixing namespace-qualified identifiers functions properly with
// namespace-aware typo correction/
namespace redecl_typo {
namespace Foo {
void BeEvil ( ) ; // expected-note {{'BeEvil' declared here}}
}
namespace Bar {
namespace Foo {
bool isGood ( ) ; // expected-note {{'Bar::Foo::isGood' declared here}}
void beEvil ( ) ;
}
}
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'?}}
return true ;
}
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'?}}
}
2012-06-18 14:11:04 +08:00
// Test behavior when a template-id is ended by a token which starts with '>'.
namespace greatergreater {
template < typename T > struct S { S ( ) ; S ( T ) ; } ;
void f ( S < int > = 0 ) ; // expected-error {{a space is required between a right angle bracket and an equals sign (use '> =')}}
// FIXME: The fix-its here overlap so -fixit mode can't apply the second one.
//void f(S<S<int>>=S<int>());
struct Shr {
template < typename T > Shr ( T ) ;
template < typename T > void operator > > = ( T ) ;
} ;
template < template < typename > > struct TemplateTemplateParam ; // expected-error {{requires 'class'}}
template < typename T > void t ( ) ;
void g ( ) {
void ( * p ) ( ) = & t < int > ;
( void ) ( & t < int > = = p ) ; // expected-error {{use '> ='}}
( void ) ( & t < int > > = p ) ; // expected-error {{use '> >'}}
( void ) ( & t < S < int > > > = p ) ; // expected-error {{use '> >'}}
( Shr ) & t < S < int > > > > = p ; // expected-error {{use '> >'}}
// FIXME: We correct this to '&t<int> > >= p;' not '&t<int> >>= p;'
//(Shr)&t<int>>>=p;
// FIXME: The fix-its here overlap.
//(void)(&t<S<int>>==p);
}
}
2012-10-12 06:55:07 +08:00
class foo {
static void test ( ) {
( void ) & i ; // expected-error{{must explicitly qualify name of member function when taking its address}}
}
int i ( ) ;
} ;
2013-03-21 01:42:13 +08:00
namespace dtor_fixit {
class foo {
~ bar ( ) { } // expected-error {{expected the class name after '~' to name a destructor}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:6-[[@LINE-1]]:9}:"foo"
} ;
}
2013-07-11 13:10:21 +08:00
namespace PR5066 {
template < typename T > struct X { } ;
X < int * p > x ; // expected-error {{type-id cannot have a name}}
}
2013-07-12 06:38:30 +08:00
2013-07-13 05:43:02 +08:00
namespace PR5898 {
class A {
public :
const char * str ( ) ;
} ;
const char * foo ( A & x )
{
return x . str . ( ) ; // expected-error {{unexpected '.' in function call; perhaps remove the '.'?}}
}
bool bar ( A x , const char * y ) {
return foo - > ( x ) = = y ; // expected-error {{unexpected '->' in function call; perhaps remove the '->'?}}
}
}
2013-08-01 04:16:17 +08:00
namespace PR15045 {
class Cl0 {
public :
int a ;
} ;
int f ( ) {
Cl0 c ;
return c - > a ; // expected-error {{member reference type 'PR15045::Cl0' is not a pointer; maybe you meant to use '.'?}}
}
}