]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaCXX/static-assert.cpp
Vendor import of clang trunk r162107:
[FreeBSD/FreeBSD.git] / test / SemaCXX / static-assert.cpp
1 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -triple=x86_64-linux-gnu
2
3 int f(); // expected-note {{declared here}}
4
5 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}}
6 static_assert(true, "true is not false");
7 static_assert(false, "false is false"); // expected-error {{static_assert failed "false is false"}}
8
9 void g() {
10     static_assert(false, "false is false"); // expected-error {{static_assert failed "false is false"}}
11 }
12
13 class C {
14     static_assert(false, "false is false"); // expected-error {{static_assert failed "false is false"}}
15 };
16
17 template<int N> struct T {
18     static_assert(N == 2, "N is not 2!"); // expected-error {{static_assert failed "N is not 2!"}}
19 };
20
21 T<1> t1; // expected-note {{in instantiation of template class 'T<1>' requested here}}
22 T<2> t2;
23
24 template<typename T> struct S {
25     static_assert(sizeof(T) > sizeof(char), "Type not big enough!"); // expected-error {{static_assert failed "Type not big enough!"}}
26 };
27
28 S<char> s1; // expected-note {{in instantiation of template class 'S<char>' requested here}}
29 S<int> s2;
30
31 static_assert(false, L"\xFFFFFFFF"); // expected-error {{static_assert failed L"\xFFFFFFFF"}}
32 static_assert(false, u"\U000317FF"); // expected-error {{static_assert failed u"\U000317FF"}}
33 // FIXME: render this as u8"\u03A9"
34 static_assert(false, u8"Ω"); // expected-error {{static_assert failed u8"\316\251"}}
35 static_assert(false, L"\u1234"); // expected-error {{static_assert failed L"\x1234"}}
36 static_assert(false, L"\x1ff" "0\x123" "fx\xfffff" "goop"); // expected-error {{static_assert failed L"\x1FF""0\x123""fx\xFFFFFgoop"}}
37
38 template<typename T> struct AlwaysFails {
39   // Only give one error here.
40   static_assert(false, ""); // expected-error {{static_assert failed}}
41 };
42 AlwaysFails<int> alwaysFails;
43
44 template<typename T> struct StaticAssertProtected {
45   static_assert(__is_literal(T), ""); // expected-error {{static_assert failed}}
46   static constexpr T t = {}; // no error here
47 };
48 struct X { ~X(); };
49 StaticAssertProtected<int> sap1;
50 StaticAssertProtected<X> sap2; // expected-note {{instantiation}}