2012-04-05 08:54:51 +08:00
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -triple=x86_64-linux-gnu
2009-03-14 08:25:26 +08:00
2011-12-15 07:32:26 +08:00
int f ( ) ; // expected-note {{declared here}}
2009-03-14 08:25:26 +08:00
2011-12-15 07:32:26 +08:00
static_assert ( f ( ) , " f " ) ; // expected-error {{static_assert expression is not an integral constant expression}} expected-note {{non-constexpr function 'f' cannot be used in a constant expression}}
2009-03-14 08:25:26 +08:00
static_assert ( true , " true is not false " ) ;
static_assert ( false , " false is false " ) ; // expected-error {{static_assert failed "false is false"}}
void g ( ) {
static_assert ( false , " false is false " ) ; // expected-error {{static_assert failed "false is false"}}
}
class C {
static_assert ( false , " false is false " ) ; // expected-error {{static_assert failed "false is false"}}
} ;
2009-03-14 08:33:21 +08:00
template < int N > struct T {
2009-03-16 02:44:04 +08:00
static_assert ( N = = 2 , " N is not 2! " ) ; // expected-error {{static_assert failed "N is not 2!"}}
2009-03-14 08:33:21 +08:00
} ;
2010-03-10 19:27:22 +08:00
T < 1 > t1 ; // expected-note {{in instantiation of template class 'T<1>' requested here}}
2009-03-16 02:44:04 +08:00
T < 2 > t2 ;
2009-03-14 08:33:21 +08:00
template < typename T > struct S {
2009-03-16 02:44:04 +08:00
static_assert ( sizeof ( T ) > sizeof ( char ) , " Type not big enough! " ) ; // expected-error {{static_assert failed "Type not big enough!"}}
2009-03-14 08:33:21 +08:00
} ;
2010-03-10 19:27:22 +08:00
S < char > s1 ; // expected-note {{in instantiation of template class 'S<char>' requested here}}
2009-03-16 02:44:04 +08:00
S < int > s2 ;
2012-04-05 08:17:44 +08:00
static_assert ( false , L " \xFFFF FFFF " ) ; // expected-error {{static_assert failed L"\xFFFFFFFF"}}
static_assert ( false , u " \U000317FF " ) ; // expected-error {{static_assert failed u"\U000317FF"}}
// FIXME: render this as u8"\u03A9"
static_assert ( false , u8 " Ω " ) ; // expected-error {{static_assert failed u8"\316\251"}}
static_assert ( false , L " \u1234 " ) ; // expected-error {{static_assert failed L"\x1234"}}
static_assert ( false , L " \x1ff " " 0 \x123 " " fx \xffff f " " goop " ) ; // expected-error {{static_assert failed L"\x1FF""0\x123""fx\xFFFFFgoop"}}
2012-07-12 06:37:56 +08:00
template < typename T > struct AlwaysFails {
// Only give one error here.
static_assert ( false , " " ) ; // expected-error {{static_assert failed}}
} ;
AlwaysFails < int > alwaysFails ;
template < typename T > struct StaticAssertProtected {
static_assert ( __is_literal ( T ) , " " ) ; // expected-error {{static_assert failed}}
static constexpr T t = { } ; // no error here
} ;
struct X { ~ X ( ) ; } ;
StaticAssertProtected < int > sap1 ;
StaticAssertProtected < X > sap2 ; // expected-note {{instantiation}}
2014-06-21 03:57:12 +08:00
2017-08-14 06:26:53 +08:00
static_assert ( true ) ; // expected-warning {{C++17 extension}}
2014-06-21 03:58:05 +08:00
static_assert ( false ) ; // expected-error-re {{failed{{$}}}} expected-warning {{extension}}