2013-03-28 10:51:21 +08:00
// RUN: %clang_cc1 %s -std=c++11 -fcxx-exceptions -fexceptions -fsyntax-only -Wignored-qualifiers -verify
2009-07-23 07:56:57 +08:00
int test1 ( ) {
throw ;
}
2009-10-02 07:25:31 +08:00
// PR5071
template < typename T > T f ( ) { }
template < typename T >
void g ( T t ) {
return t * 2 ; // okay
}
template < typename T >
T h ( ) {
return 17 ;
}
2010-07-14 14:36:18 +08:00
// Don't warn on cv-qualified class return types, only scalar return types.
namespace ignored_quals {
struct S { } ;
const S class_c ( ) ;
const volatile S class_cv ( ) ;
const int scalar_c ( ) ; // expected-warning{{'const' type qualifier on return type has no effect}}
2011-02-24 02:51:59 +08:00
int const scalar_c2 ( ) ; // expected-warning{{'const' type qualifier on return type has no effect}}
const
char *
const // expected-warning{{'const' type qualifier on return type has no effect}}
f ( ) ;
char
const *
const // expected-warning{{'const' type qualifier on return type has no effect}}
g ( ) ;
char * const h ( ) ; // expected-warning{{'const' type qualifier on return type has no effect}}
char * volatile i ( ) ; // expected-warning{{'volatile' type qualifier on return type has no effect}}
2011-06-04 01:37:26 +08:00
char *
volatile // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
const
j ( ) ;
2010-07-14 14:36:18 +08:00
const volatile int scalar_cv ( ) ; // expected-warning{{'const volatile' type qualifiers on return type have no effect}}
2013-03-28 10:51:21 +08:00
// FIXME: Maintain enough information that we can point the diagnostic at the 'volatile' keyword.
const
int S : : *
volatile
mixed_ret ( ) ; // expected-warning {{'volatile' type qualifier on return type has no effect}}
const int volatile // expected-warning {{'const volatile' type qualifiers on return type have no effect}}
( ( ( parens ( ) ) ) ) ;
2013-03-28 11:27:52 +08:00
_Atomic ( int ) atomic ( ) ;
2013-03-28 10:51:21 +08:00
_Atomic // expected-warning {{'_Atomic' type qualifier on return type has no effect}}
int
atomic ( ) ;
2020-10-29 06:23:09 +08:00
auto trailing_return_type ( ) - >
const int ; // expected-warning {{'const' type qualifier on return type has no effect}}
auto trailing_return_type_lambda = [ ] ( const int & x ) - >
const int // expected-warning {{'const' type qualifier on return type has no effect}}
{ return x ; } ;
2013-03-28 10:51:21 +08:00
const int ret_array ( ) [ 4 ] ; // expected-error {{cannot return array}}
2010-07-14 14:36:18 +08:00
}
2011-03-02 01:04:42 +08:00
namespace PR9328 {
typedef char * PCHAR ;
class Test
{
const PCHAR GetName ( ) { return 0 ; } // expected-warning{{'const' type qualifier on return type has no effect}}
} ;
}
2011-03-11 12:56:58 +08:00
class foo {
2013-03-28 10:51:21 +08:00
operator const int ( ) ;
2011-03-11 12:56:58 +08:00
operator int * const ( ) ;
} ;
2011-06-01 15:44:31 +08:00
namespace PR10057 {
struct S {
~ S ( ) ;
} ;
template < class VarType >
void Test ( const VarType & value ) {
return S ( ) = value ;
}
}
2011-07-01 01:20:18 +08:00
namespace return_has_expr {
struct S {
S ( ) {
return 42 ; // expected-error {{constructor 'S' should not return a value}}
}
~ S ( ) {
return 42 ; // expected-error {{destructor '~S' should not return a value}}
}
} ;
}
2013-12-04 01:10:08 +08:00
// rdar://15366494
// pr17759
namespace ctor_returns_void {
void f ( ) { }
struct S {
2020-07-19 03:44:06 +08:00
S ( ) { return f ( ) ; } // expected-error {{constructor 'S' must not return void expression}}
2013-12-04 01:10:08 +08:00
~ S ( ) { return f ( ) ; } // expected-error {{destructor '~S' must not return void expression}}
} ;
2020-07-19 03:44:06 +08:00
template < typename T > struct ST {
ST ( ) { return f ( ) ; } // expected-error {{constructor 'ST<T>' must not return void expression}}
// expected-error@-1 {{constructor 'ST' must not return void expression}}
~ ST ( ) { return f ( ) ; } // expected-error {{destructor '~ST<T>' must not return void expression}}
// expected-error@-1 {{destructor '~ST' must not return void expression}}
} ;
ST < int > st ; // expected-note {{in instantiation of member function 'ctor_returns_void::ST<int>::ST'}}
// expected-note@-1 {{in instantiation of member function 'ctor_returns_void::ST<int>::~ST'}}
2013-12-04 01:10:08 +08:00
}
2015-01-05 04:32:12 +08:00
void cxx_unresolved_expr ( ) {
// The use of an undeclared variable tricks clang into building a
// CXXUnresolvedConstructExpr, and the missing ')' gives it an invalid source
// location for its rparen. Check that emitting a diag on the range of the
// expr doesn't assert.
2016-07-01 04:24:30 +08:00
return int ( undeclared , 4 ; // expected-error {{expected ')'}} expected-note{{to match this '('}} expected-error {{use of undeclared identifier 'undeclared'}}
2015-01-05 04:32:12 +08:00
}