1 // RUN: %clang_cc1 %s -std=c++17 -fsyntax-only -fcxx-exceptions -verify
4 void f() [[clang::annotate_type("foo")]];
5 [[clang::annotate_type("foo")]] void g(); // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
8 template <typename T1
, typename T2
> struct is_same
{
9 static constexpr bool value
= false;
12 template <typename T1
> struct is_same
<T1
, T1
> {
13 static constexpr bool value
= true;
16 static_assert(is_same
<int, int [[clang::annotate_type("foo")]]>::value
);
17 static_assert(is_same
<int [[clang::annotate_type("foo")]],
18 int [[clang::annotate_type("bar")]]>::value
);
19 static_assert(is_same
<int *, int *[[clang::annotate_type("foo")]]>::value
);
21 // Cannot overload on types that only differ by `annotate_type` attribute.
22 void f(int) {} // expected-note {{previous definition is here}}
23 void f(int [[clang::annotate_type("foo")]]) {} // expected-error {{redefinition of 'f'}}
25 // Cannot specialize on types that only differ by `annotate_type` attribute.
26 template <class T
> struct S2
{};
28 template <> struct S2
<int> {}; // expected-note {{previous definition is here}}
31 struct S2
<int [[clang::annotate_type("foo")]]> {}; // expected-error {{redefinition of 'S2<int>'}}
33 // Test that the attribute supports parameter pack expansion.
34 template <int... Is
> void variadic_func_template() {
35 int [[clang::annotate_type("foo", Is
...)]] val
;
37 int f2() { variadic_func_template
<1, 2, 3>(); }
39 // Make sure we correctly diagnose wrong number of arguments for
40 // [[clang::annotate_type]] inside a template argument.
41 template <typename Ty
> void func_template();
43 func_template
<int [[clang::annotate_type()]]>(); // expected-error {{'annotate_type' attribute takes at least 1 argument}}
46 // More error cases: Prohibit adding the attribute to declarations.
47 // Different declarations hit different code paths, so they need separate tests.
48 namespace [[clang::annotate_type("foo")]] my_namespace
{} // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
49 struct [[clang::annotate_type("foo")]] S3
; // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
50 struct [[clang::annotate_type("foo")]] S3
{ // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
51 [[clang::annotate_type("foo")]] int member
; // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
54 for ([[clang::annotate_type("foo")]] int i
= 0; i
< 42; ++i
) {} // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
55 for (; [[clang::annotate_type("foo")]] bool b
= false;) {} // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
56 while ([[clang::annotate_type("foo")]] bool b
= false) {} // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
57 if ([[clang::annotate_type("foo")]] bool b
= false) {} // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
59 } catch ([[clang::annotate_type("foo")]] int i
) { // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
63 [[clang::annotate_type("foo")]] T var_template
; // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}
64 [[clang::annotate_type("foo")]] extern "C" int extern_c_func(); // expected-error {{an attribute list cannot appear here}}
65 extern "C" [[clang::annotate_type("foo")]] int extern_c_func(); // expected-error {{'annotate_type' attribute cannot be applied to a declaration}}