1 // RUN: %clang_cc1 -std=gnu++20 -fsyntax-only -verify %s
3 template<bool If
, typename Type
>
8 template<typename Type
>
9 struct enable_if
<false, Type
> {};
11 template<typename T1
, typename T2
>
13 static constexpr bool value
= false;
17 struct is_same
<T1
, T1
> {
18 static constexpr bool value
= true;
21 constexpr const char *str() {
25 template<typename T
, typename enable_if
<!is_same
<int, T
>::value
, int>::type
= 0>
26 constexpr T
fail_on_int(T t
) {return t
;}
27 // expected-note@-1 {{candidate template ignored: requirement}}
30 template<typename T
, T v
>
32 [[clang::annotate("test", fail_on_int(v
))]] void t() {}
33 // expected-error@-1 {{no matching function for call to 'fail_on_int'}}
34 [[clang::annotate("test", (typename enable_if
<!is_same
<long, T
>::value
, int>::type
)v
)]] void t1() {}
35 // expected-error@-1 {{failed requirement}}
38 // expected-note@-1 {{in instantiation of template class}}
40 // expected-note@-1 {{in instantiation of template class}}
41 A
<unsigned long, 6> a2
;
45 [[clang::annotate("test", ((void)T
{}, 9))]] void t() {}
46 // expected-error@-1 {{illegal initializer type 'void'}}
50 // expected-note@-1 {{in instantiation of template class}}
54 int g_i
; // expected-note {{declared here}}
56 [[clang::annotate("test", "arg")]] void t3() {}
58 template <typename T
, T V
>
60 static T b
; // expected-note {{declared here}}
61 static constexpr T cb
= V
;
62 template <typename T1
, T1 V1
>
64 static T1 f
; // expected-note {{declared here}}
65 static constexpr T1 cf
= V1
;
66 int v
__attribute__((annotate("v_ann_0", str(), 90, V
, g_i
))) __attribute__((annotate("v_ann_1", V1
)));
67 // expected-error@-1 {{'annotate' attribute requires parameter 4 to be a constant expression}}
68 // expected-note@-2 {{is not allowed in a constant expression}}
69 [[clang::annotate("qdwqwd", cf
, cb
)]] void t() {}
70 [[clang::annotate("qdwqwd", f
, cb
)]] void t1() {}
71 // expected-error@-1 {{'annotate' attribute requires parameter 1 to be a constant expression}}
72 // expected-note@-2 {{is not allowed in a constant expression}}
73 [[clang::annotate("jui", b
, cf
)]] void t2() {}
74 // expected-error@-1 {{'annotate' attribute requires parameter 1 to be a constant expression}}
75 // expected-note@-2 {{is not allowed in a constant expression}}
76 [[clang::annotate("jui", ((void)b
, 0), cf
)]] [[clang::annotate("jui", &b
, cf
, &foo::t2
, str())]] void t3() {}
80 static B
<int long, -1>::foo
<unsigned, 9> gf
; // expected-note {{in instantiation of}}
81 static B
<int long, -2> gf1
;
89 [[clang::annotate("test", I
)]] int v
= 0; // expected-note {{declared here}}
90 [[clang::annotate("test", v
)]] int v2
= 0;
91 // expected-error@-1 {{'annotate' attribute requires parameter 1 to be a constant expression}}
92 // expected-note@-2 {{is not allowed in a constant expression}}
93 [[clang::annotate("test", rtyui
)]] int v3
= 0;
94 // expected-error@-1 {{use of undeclared identifier 'rtyui'}}
106 [[clang::annotate("vlas are awful", sizeof(vla
))]] int i
= 0; // reject, the sizeof is not unevaluated
107 // expected-error@-1 {{'annotate' attribute requires parameter 1 to be a constant expression}}
108 // expected-note@-2 {{subexpression not valid in a constant expression}}
109 [[clang::annotate("_Generic selection expression should be fine", _Generic(n
, int : 0, default : 1))]]
110 int j
= 0; // second arg should resolve to 0 fine
113 [[clang::annotate("function designators?", designator
)]] int k
= 0; // Should work?
116 [[clang::annotate("function designators?", self
)]] int k
= 0;
122 constexpr int foldable_but_invalid() {
124 // expected-note@-1 {{allocation performed here was not deallocated}}
128 [[clang::annotate("", foldable_but_invalid())]] void f1() {}
129 // expected-error@-1 {{'annotate' attribute requires parameter 1 to be a constant expression}}