1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 -Wc++14-compat %s 2f4a2713aSLionel Sambuc 3f4a2713aSLionel Sambuc // Need std::initializer_list 4f4a2713aSLionel Sambuc namespace std { 5f4a2713aSLionel Sambuc typedef decltype(sizeof(int)) size_t; 6f4a2713aSLionel Sambuc 7f4a2713aSLionel Sambuc // libc++'s implementation 8f4a2713aSLionel Sambuc template <class _E> 9f4a2713aSLionel Sambuc class initializer_list 10f4a2713aSLionel Sambuc { 11f4a2713aSLionel Sambuc const _E* __begin_; 12f4a2713aSLionel Sambuc size_t __size_; 13f4a2713aSLionel Sambuc initializer_list(const _E * __b,size_t __s)14f4a2713aSLionel Sambuc initializer_list(const _E* __b, size_t __s) 15f4a2713aSLionel Sambuc : __begin_(__b), 16f4a2713aSLionel Sambuc __size_(__s) 17f4a2713aSLionel Sambuc {} 18f4a2713aSLionel Sambuc 19f4a2713aSLionel Sambuc public: 20f4a2713aSLionel Sambuc typedef _E value_type; 21f4a2713aSLionel Sambuc typedef const _E& reference; 22f4a2713aSLionel Sambuc typedef const _E& const_reference; 23f4a2713aSLionel Sambuc typedef size_t size_type; 24f4a2713aSLionel Sambuc 25f4a2713aSLionel Sambuc typedef const _E* iterator; 26f4a2713aSLionel Sambuc typedef const _E* const_iterator; 27f4a2713aSLionel Sambuc initializer_list()28f4a2713aSLionel Sambuc initializer_list() : __begin_(nullptr), __size_(0) {} 29f4a2713aSLionel Sambuc size() const30f4a2713aSLionel Sambuc size_t size() const {return __size_;} begin() const31f4a2713aSLionel Sambuc const _E* begin() const {return __begin_;} end() const32f4a2713aSLionel Sambuc const _E* end() const {return __begin_ + __size_;} 33f4a2713aSLionel Sambuc }; 34f4a2713aSLionel Sambuc } 35f4a2713aSLionel Sambuc 36f4a2713aSLionel Sambuc 37f4a2713aSLionel Sambuc // Declaration syntax checks 38f4a2713aSLionel Sambuc [[]] int before_attr; 39f4a2713aSLionel Sambuc int [[]] between_attr; 40f4a2713aSLionel Sambuc const [[]] int between_attr_2 = 0; // expected-error {{an attribute list cannot appear here}} 41f4a2713aSLionel Sambuc int after_attr [[]]; 42f4a2713aSLionel Sambuc int * [[]] ptr_attr; 43f4a2713aSLionel Sambuc int & [[]] ref_attr = after_attr; 44f4a2713aSLionel Sambuc int & [[unknown]] ref_attr_2 = after_attr; // expected-warning {{unknown attribute 'unknown' ignored}} 45f4a2713aSLionel Sambuc int & [[noreturn]] ref_attr_3 = after_attr; // expected-error {{'noreturn' attribute cannot be applied to types}} 46f4a2713aSLionel Sambuc int && [[]] rref_attr = 0; 47f4a2713aSLionel Sambuc int array_attr [1] [[]]; 48f4a2713aSLionel Sambuc alignas(8) int aligned_attr; 49f4a2713aSLionel Sambuc [[test::valid(for 42 [very] **** '+' symbols went on a trip and had a "good"_time; the end.)]] int garbage_attr; // expected-warning {{unknown attribute 'valid' ignored}} 50f4a2713aSLionel Sambuc [[,,,static, class, namespace,, inline, constexpr, mutable,, bitand, bitor::compl(!.*_ Cx.!U^*R),,,]] int more_garbage_attr; // expected-warning {{unknown attribute 'static' ignored}} \ 51f4a2713aSLionel Sambuc // expected-warning {{unknown attribute 'class' ignored}} \ 52f4a2713aSLionel Sambuc // expected-warning {{unknown attribute 'namespace' ignored}} \ 53f4a2713aSLionel Sambuc // expected-warning {{unknown attribute 'inline' ignored}} \ 54f4a2713aSLionel Sambuc // expected-warning {{unknown attribute 'constexpr' ignored}} \ 55f4a2713aSLionel Sambuc // expected-warning {{unknown attribute 'mutable' ignored}} \ 56f4a2713aSLionel Sambuc // expected-warning {{unknown attribute 'bitand' ignored}} \ 57f4a2713aSLionel Sambuc // expected-warning {{unknown attribute 'compl' ignored}} 58f4a2713aSLionel Sambuc [[u8"invalid!"]] int invalid_string_attr; // expected-error {{expected ']'}} 59f4a2713aSLionel Sambuc void fn_attr () [[]]; 60f4a2713aSLionel Sambuc void noexcept_fn_attr () noexcept [[]]; 61f4a2713aSLionel Sambuc struct MemberFnOrder { 62f4a2713aSLionel Sambuc virtual void f() const volatile && noexcept [[]] final = 0; 63f4a2713aSLionel Sambuc }; 64f4a2713aSLionel Sambuc struct [[]] struct_attr; 65f4a2713aSLionel Sambuc class [[]] class_attr {}; 66f4a2713aSLionel Sambuc union [[]] union_attr; 67f4a2713aSLionel Sambuc 68f4a2713aSLionel Sambuc // Checks attributes placed at wrong syntactic locations of class specifiers. 69f4a2713aSLionel Sambuc class [[]] [[]] 70f4a2713aSLionel Sambuc attr_after_class_name_decl [[]] [[]]; // expected-error {{an attribute list cannot appear here}} 71f4a2713aSLionel Sambuc 72f4a2713aSLionel Sambuc class [[]] [[]] 73f4a2713aSLionel Sambuc attr_after_class_name_definition [[]] [[]] [[]]{}; // expected-error {{an attribute list cannot appear here}} 74f4a2713aSLionel Sambuc 75f4a2713aSLionel Sambuc class [[]] c {}; 76f4a2713aSLionel Sambuc class c [[]] [[]] x; 77f4a2713aSLionel Sambuc class c [[]] [[]] y [[]] [[]]; 78f4a2713aSLionel Sambuc class c final [(int){0}]; 79f4a2713aSLionel Sambuc 80f4a2713aSLionel Sambuc class base {}; 81f4a2713aSLionel Sambuc class [[]] [[]] final_class 82f4a2713aSLionel Sambuc alignas(float) [[]] final // expected-error {{an attribute list cannot appear here}} 83f4a2713aSLionel Sambuc alignas(float) [[]] [[]] alignas(float): base{}; // expected-error {{an attribute list cannot appear here}} 84f4a2713aSLionel Sambuc 85f4a2713aSLionel Sambuc class [[]] [[]] final_class_another 86f4a2713aSLionel Sambuc [[]] [[]] alignas(16) final // expected-error {{an attribute list cannot appear here}} 87f4a2713aSLionel Sambuc [[]] [[]] alignas(16) [[]]{}; // expected-error {{an attribute list cannot appear here}} 88f4a2713aSLionel Sambuc 89*0a6a1f1dSLionel Sambuc // The diagnostics here don't matter much, this just shouldn't crash: 90*0a6a1f1dSLionel Sambuc class C final [[deprecated(l]] {}); // expected-error {{use of undeclared identifier}} expected-error {{expected ']'}} expected-error {{an attribute list cannot appear here}} expected-error {{expected unqualified-id}} 91*0a6a1f1dSLionel Sambuc class D final alignas ([l) {}]{}); // expected-error {{expected ',' or ']' in lambda capture list}} expected-error {{an attribute list cannot appear here}} 92*0a6a1f1dSLionel Sambuc 93f4a2713aSLionel Sambuc [[]] struct with_init_declarators {} init_declarator; 94f4a2713aSLionel Sambuc [[]] struct no_init_declarators; // expected-error {{an attribute list cannot appear here}} 95f4a2713aSLionel Sambuc template<typename> [[]] struct no_init_declarators_template; // expected-error {{an attribute list cannot appear here}} 96f4a2713aSLionel Sambuc void fn_with_structs() { 97f4a2713aSLionel Sambuc [[]] struct with_init_declarators {} init_declarator; 98f4a2713aSLionel Sambuc [[]] struct no_init_declarators; // expected-error {{an attribute list cannot appear here}} 99f4a2713aSLionel Sambuc } 100f4a2713aSLionel Sambuc [[]]; 101f4a2713aSLionel Sambuc struct ctordtor { 102f4a2713aSLionel Sambuc [[]] ctordtor(); 103f4a2713aSLionel Sambuc [[]] ~ctordtor(); 104f4a2713aSLionel Sambuc }; 105f4a2713aSLionel Sambuc [[]] ctordtor::ctordtor() {} 106f4a2713aSLionel Sambuc [[]] ctordtor::~ctordtor() {} 107f4a2713aSLionel Sambuc extern "C++" [[]] int extern_attr; 108f4a2713aSLionel Sambuc template <typename T> [[]] void template_attr (); 109f4a2713aSLionel Sambuc [[]] [[]] int [[]] [[]] multi_attr [[]] [[]]; 110f4a2713aSLionel Sambuc 111f4a2713aSLionel Sambuc int comma_attr [[,]]; 112f4a2713aSLionel Sambuc int scope_attr [[foo::]]; // expected-error {{expected identifier}} 113f4a2713aSLionel Sambuc int (paren_attr) [[]]; // expected-error {{an attribute list cannot appear here}} 114f4a2713aSLionel Sambuc unsigned [[]] int attr_in_decl_spec; // expected-error {{an attribute list cannot appear here}} 115f4a2713aSLionel Sambuc unsigned [[]] int [[]] const double_decl_spec = 0; // expected-error 2{{an attribute list cannot appear here}} 116f4a2713aSLionel Sambuc class foo { 117f4a2713aSLionel Sambuc void const_after_attr () [[]] const; // expected-error {{expected ';'}} 118f4a2713aSLionel Sambuc }; 119f4a2713aSLionel Sambuc extern "C++" [[]] { } // expected-error {{an attribute list cannot appear here}} 120f4a2713aSLionel Sambuc [[]] template <typename T> void before_template_attr (); // expected-error {{an attribute list cannot appear here}} 121f4a2713aSLionel Sambuc [[]] namespace ns { int i; } // expected-error {{an attribute list cannot appear here}} expected-note {{declared here}} 122f4a2713aSLionel Sambuc [[]] static_assert(true, ""); //expected-error {{an attribute list cannot appear here}} 123f4a2713aSLionel Sambuc [[]] asm(""); // expected-error {{an attribute list cannot appear here}} 124f4a2713aSLionel Sambuc 125f4a2713aSLionel Sambuc [[]] using ns::i; // expected-error {{an attribute list cannot appear here}} 126f4a2713aSLionel Sambuc [[unknown]] using namespace ns; // expected-warning {{unknown attribute 'unknown' ignored}} 127*0a6a1f1dSLionel Sambuc [[noreturn]] using namespace ns; // expected-error {{'noreturn' attribute only applies to functions}} 128*0a6a1f1dSLionel Sambuc namespace [[]] ns2 {} // expected-warning {{attributes on a namespace declaration are incompatible with C++ standards before C++1z}} 129f4a2713aSLionel Sambuc 130f4a2713aSLionel Sambuc using [[]] alignas(4) [[]] ns::i; // expected-error {{an attribute list cannot appear here}} 131f4a2713aSLionel Sambuc using [[]] alignas(4) [[]] foobar = int; // expected-error {{an attribute list cannot appear here}} expected-error {{'alignas' attribute only applies to}} 132f4a2713aSLionel Sambuc 133f4a2713aSLionel Sambuc void bad_attributes_in_do_while() { 134f4a2713aSLionel Sambuc do {} while ( 135f4a2713aSLionel Sambuc [[ns::i); // expected-error {{expected ']'}} \ 136f4a2713aSLionel Sambuc // expected-note {{to match this '['}} \ 137f4a2713aSLionel Sambuc // expected-error {{expected expression}} 138f4a2713aSLionel Sambuc do {} while ( 139f4a2713aSLionel Sambuc [[a]b ns::i); // expected-error {{expected ']'}} \ 140f4a2713aSLionel Sambuc // expected-note {{to match this '['}} \ 141f4a2713aSLionel Sambuc // expected-error {{expected expression}} 142f4a2713aSLionel Sambuc do {} while ( 143f4a2713aSLionel Sambuc [[ab]ab] ns::i); // expected-error {{an attribute list cannot appear here}} 144f4a2713aSLionel Sambuc do {} while ( // expected-note {{to match this '('}} 145f4a2713aSLionel Sambuc alignas(4 ns::i; // expected-note {{to match this '('}} 146f4a2713aSLionel Sambuc } // expected-error 2{{expected ')'}} expected-error {{expected expression}} 147f4a2713aSLionel Sambuc 148f4a2713aSLionel Sambuc [[]] using T = int; // expected-error {{an attribute list cannot appear here}} 149f4a2713aSLionel Sambuc using T [[]] = int; // ok 150f4a2713aSLionel Sambuc template<typename T> using U [[]] = T; 151f4a2713aSLionel Sambuc using ns::i [[]]; // expected-error {{an attribute list cannot appear here}} 152f4a2713aSLionel Sambuc using [[]] ns::i; // expected-error {{an attribute list cannot appear here}} 153f4a2713aSLionel Sambuc using T [[unknown]] = int; // expected-warning {{unknown attribute 'unknown' ignored}} 154*0a6a1f1dSLionel Sambuc using T [[noreturn]] = int; // expected-error {{'noreturn' attribute only applies to functions}} 155f4a2713aSLionel Sambuc using V = int; // expected-note {{previous}} 156f4a2713aSLionel Sambuc using V [[gnu::vector_size(16)]] = int; // expected-error {{redefinition with different types}} 157f4a2713aSLionel Sambuc 158f4a2713aSLionel Sambuc auto trailing() -> [[]] const int; // expected-error {{an attribute list cannot appear here}} 159f4a2713aSLionel Sambuc auto trailing() -> const [[]] int; // expected-error {{an attribute list cannot appear here}} 160f4a2713aSLionel Sambuc auto trailing() -> const int [[]]; 161f4a2713aSLionel Sambuc auto trailing_2() -> struct struct_attr [[]]; 162f4a2713aSLionel Sambuc 163f4a2713aSLionel Sambuc namespace N { 164f4a2713aSLionel Sambuc struct S {}; 165f4a2713aSLionel Sambuc }; 166f4a2713aSLionel Sambuc template<typename> struct Template {}; 167f4a2713aSLionel Sambuc 168f4a2713aSLionel Sambuc // FIXME: Improve this diagnostic 169f4a2713aSLionel Sambuc struct [[]] N::S s; // expected-error {{an attribute list cannot appear here}} 170f4a2713aSLionel Sambuc struct [[]] Template<int> t; // expected-error {{an attribute list cannot appear here}} 171f4a2713aSLionel Sambuc struct [[]] ::template Template<int> u; // expected-error {{an attribute list cannot appear here}} 172f4a2713aSLionel Sambuc template struct [[]] Template<char>; // expected-error {{an attribute list cannot appear here}} 173f4a2713aSLionel Sambuc template <> struct [[]] Template<void>; 174f4a2713aSLionel Sambuc 175f4a2713aSLionel Sambuc enum [[]] E1 {}; 176f4a2713aSLionel Sambuc enum [[]] E2; // expected-error {{forbids forward references}} 177f4a2713aSLionel Sambuc enum [[]] E1; 178f4a2713aSLionel Sambuc enum [[]] E3 : int; 179f4a2713aSLionel Sambuc enum [[]] { 180*0a6a1f1dSLionel Sambuc k_123 [[]] = 123 // expected-warning {{attributes on an enumerator declaration are incompatible with C++ standards before C++1z}} 181f4a2713aSLionel Sambuc }; 182f4a2713aSLionel Sambuc enum [[]] E1 e; // expected-error {{an attribute list cannot appear here}} 183f4a2713aSLionel Sambuc enum [[]] class E4 { }; // expected-error {{an attribute list cannot appear here}} 184f4a2713aSLionel Sambuc enum struct [[]] E5; 185f4a2713aSLionel Sambuc 186f4a2713aSLionel Sambuc struct S { 187f4a2713aSLionel Sambuc friend int f [[]] (); // expected-FIXME{{an attribute list cannot appear here}} 188f4a2713aSLionel Sambuc friend int f1 [[noreturn]] (); //expected-error{{an attribute list cannot appear here}} 189f4a2713aSLionel Sambuc friend int f2 [[]] [[noreturn]] () {} 190f4a2713aSLionel Sambuc [[]] friend int g(); // expected-error{{an attribute list cannot appear here}} 191f4a2713aSLionel Sambuc [[]] friend int h() { 192f4a2713aSLionel Sambuc } 193f4a2713aSLionel Sambuc [[]] friend int f3(), f4(), f5(); // expected-error{{an attribute list cannot appear here}} 194f4a2713aSLionel Sambuc friend int f6 [[noreturn]] (), f7 [[noreturn]] (), f8 [[noreturn]] (); // expected-error3 {{an attribute list cannot appear here}} 195f4a2713aSLionel Sambuc friend class [[]] C; // expected-error{{an attribute list cannot appear here}} 196f4a2713aSLionel Sambuc [[]] friend class D; // expected-error{{an attribute list cannot appear here}} 197f4a2713aSLionel Sambuc [[]] friend int; // expected-error{{an attribute list cannot appear here}} 198f4a2713aSLionel Sambuc }; 199f4a2713aSLionel Sambuc template<typename T> void tmpl(T) {} 200f4a2713aSLionel Sambuc template void tmpl [[]] (int); // expected-FIXME {{an attribute list cannot appear here}} 201f4a2713aSLionel Sambuc template [[]] void tmpl(char); // expected-error {{an attribute list cannot appear here}} 202f4a2713aSLionel Sambuc template void [[]] tmpl(short); 203f4a2713aSLionel Sambuc 204f4a2713aSLionel Sambuc // Argument tests 205f4a2713aSLionel Sambuc alignas int aligned_no_params; // expected-error {{expected '('}} 206f4a2713aSLionel Sambuc alignas(i) int aligned_nonconst; // expected-error {{'aligned' attribute requires integer constant}} expected-note {{read of non-const variable 'i'}} 207f4a2713aSLionel Sambuc 208f4a2713aSLionel Sambuc // Statement tests 209f4a2713aSLionel Sambuc void foo () { 210f4a2713aSLionel Sambuc [[]] ; 211f4a2713aSLionel Sambuc [[]] { } 212f4a2713aSLionel Sambuc [[]] if (0) { } 213f4a2713aSLionel Sambuc [[]] for (;;); 214f4a2713aSLionel Sambuc [[]] do { 215f4a2713aSLionel Sambuc [[]] continue; 216f4a2713aSLionel Sambuc } while (0); 217f4a2713aSLionel Sambuc [[]] while (0); 218f4a2713aSLionel Sambuc 219f4a2713aSLionel Sambuc [[]] switch (i) { 220f4a2713aSLionel Sambuc [[]] case 0: 221f4a2713aSLionel Sambuc [[]] default: 222f4a2713aSLionel Sambuc [[]] break; 223f4a2713aSLionel Sambuc } 224f4a2713aSLionel Sambuc 225f4a2713aSLionel Sambuc [[]] goto there; 226f4a2713aSLionel Sambuc [[]] there: 227f4a2713aSLionel Sambuc 228f4a2713aSLionel Sambuc [[]] try { 229f4a2713aSLionel Sambuc } [[]] catch (...) { // expected-error {{an attribute list cannot appear here}} 230f4a2713aSLionel Sambuc } 231f4a2713aSLionel Sambuc struct S { int arr[2]; } s; 232f4a2713aSLionel Sambuc (void)s.arr[ [] { return 0; }() ]; // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}} 233f4a2713aSLionel Sambuc int n = __builtin_offsetof(S, arr[ [] { return 0; }() ]); // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}} 234f4a2713aSLionel Sambuc 235f4a2713aSLionel Sambuc void bar [[noreturn]] ([[]] int i, [[]] int j); 236f4a2713aSLionel Sambuc using FuncType = void ([[]] int); 237f4a2713aSLionel Sambuc void baz([[]]...); // expected-error {{expected parameter declarator}} 238f4a2713aSLionel Sambuc 239f4a2713aSLionel Sambuc [[]] return; 240f4a2713aSLionel Sambuc } 241f4a2713aSLionel Sambuc 242f4a2713aSLionel Sambuc template<typename...Ts> void variadic() { 243f4a2713aSLionel Sambuc void bar [[noreturn...]] (); // expected-error {{attribute 'noreturn' cannot be used as an attribute pack}} 244f4a2713aSLionel Sambuc } 245f4a2713aSLionel Sambuc 246f4a2713aSLionel Sambuc // Expression tests 247f4a2713aSLionel Sambuc void bar () { 248f4a2713aSLionel Sambuc // FIXME: GCC accepts [[gnu::noreturn]] on a lambda, even though it appertains 249f4a2713aSLionel Sambuc // to the operator()'s type, and GCC does not otherwise accept attributes 250f4a2713aSLionel Sambuc // applied to types. Use that to test this. 251f4a2713aSLionel Sambuc [] () [[gnu::noreturn]] { return; } (); // expected-warning {{attribute 'noreturn' ignored}} FIXME-error {{should not return}} 252f4a2713aSLionel Sambuc [] () [[gnu::noreturn]] { throw; } (); // expected-warning {{attribute 'noreturn' ignored}} 253f4a2713aSLionel Sambuc new int[42][[]][5][[]]{}; 254f4a2713aSLionel Sambuc } 255f4a2713aSLionel Sambuc 256f4a2713aSLionel Sambuc // Condition tests 257f4a2713aSLionel Sambuc void baz () { 258f4a2713aSLionel Sambuc if ([[unknown]] bool b = true) { // expected-warning {{unknown attribute 'unknown' ignored}} 259f4a2713aSLionel Sambuc switch ([[unknown]] int n { 42 }) { // expected-warning {{unknown attribute 'unknown' ignored}} 260f4a2713aSLionel Sambuc default: 261f4a2713aSLionel Sambuc for ([[unknown]] int n = 0; [[unknown]] char b = n < 5; ++b) { // expected-warning 2{{unknown attribute 'unknown' ignored}} 262f4a2713aSLionel Sambuc } 263f4a2713aSLionel Sambuc } 264f4a2713aSLionel Sambuc } 265f4a2713aSLionel Sambuc int x; 266f4a2713aSLionel Sambuc // An attribute can be applied to an expression-statement, such as the first 267f4a2713aSLionel Sambuc // statement in a for. But it can't be applied to a condition which is an 268f4a2713aSLionel Sambuc // expression. 269f4a2713aSLionel Sambuc for ([[]] x = 0; ; ) {} // expected-error {{an attribute list cannot appear here}} 270f4a2713aSLionel Sambuc for (; [[]] x < 5; ) {} // expected-error {{an attribute list cannot appear here}} 271f4a2713aSLionel Sambuc while ([[]] bool k { false }) { 272f4a2713aSLionel Sambuc } 273f4a2713aSLionel Sambuc while ([[]] true) { // expected-error {{an attribute list cannot appear here}} 274f4a2713aSLionel Sambuc } 275f4a2713aSLionel Sambuc do { 276f4a2713aSLionel Sambuc } while ([[]] false); // expected-error {{an attribute list cannot appear here}} 277f4a2713aSLionel Sambuc 278f4a2713aSLionel Sambuc for ([[unknown]] int n : { 1, 2, 3 }) { // expected-warning {{unknown attribute 'unknown' ignored}} 279f4a2713aSLionel Sambuc } 280f4a2713aSLionel Sambuc } 281f4a2713aSLionel Sambuc 282f4a2713aSLionel Sambuc enum class __attribute__((visibility("hidden"))) SecretKeepers { 283f4a2713aSLionel Sambuc one, /* rest are deprecated */ two, three 284f4a2713aSLionel Sambuc }; 285f4a2713aSLionel Sambuc enum class [[]] EvenMoreSecrets {}; 286f4a2713aSLionel Sambuc 287f4a2713aSLionel Sambuc namespace arguments { 288f4a2713aSLionel Sambuc void f[[gnu::format(printf, 1, 2)]](const char*, ...); 289*0a6a1f1dSLionel Sambuc void g() [[unknown::foo(ignore arguments for unknown attributes, even with symbols!)]]; // expected-warning {{unknown attribute 'foo' ignored}} 290*0a6a1f1dSLionel Sambuc [[deprecated("with argument")]] int i; 291f4a2713aSLionel Sambuc } 292f4a2713aSLionel Sambuc 293f4a2713aSLionel Sambuc // Forbid attributes on decl specifiers. 294f4a2713aSLionel Sambuc unsigned [[gnu::used]] static int [[gnu::unused]] v1; // expected-error {{'unused' attribute cannot be applied to types}} \ 295f4a2713aSLionel Sambuc expected-error {{an attribute list cannot appear here}} 296f4a2713aSLionel Sambuc typedef [[gnu::used]] unsigned long [[gnu::unused]] v2; // expected-error {{'unused' attribute cannot be applied to types}} \ 297f4a2713aSLionel Sambuc expected-error {{an attribute list cannot appear here}} 298f4a2713aSLionel Sambuc int [[carries_dependency]] foo(int [[carries_dependency]] x); // expected-error 2{{'carries_dependency' attribute cannot be applied to types}} 299f4a2713aSLionel Sambuc 300f4a2713aSLionel Sambuc // Forbid [[gnu::...]] attributes on declarator chunks. 301f4a2713aSLionel Sambuc int *[[gnu::unused]] v3; // expected-warning {{attribute 'unused' ignored}} 302f4a2713aSLionel Sambuc int v4[2][[gnu::unused]]; // expected-warning {{attribute 'unused' ignored}} 303f4a2713aSLionel Sambuc int v5()[[gnu::unused]]; // expected-warning {{attribute 'unused' ignored}} 304f4a2713aSLionel Sambuc 305f4a2713aSLionel Sambuc [[attribute_declaration]]; // expected-warning {{unknown attribute 'attribute_declaration' ignored}} 306*0a6a1f1dSLionel Sambuc [[noreturn]]; // expected-error {{'noreturn' attribute only applies to functions}} 307f4a2713aSLionel Sambuc [[carries_dependency]]; // expected-error {{'carries_dependency' attribute only applies to functions, methods, and parameters}} 308f4a2713aSLionel Sambuc 309f4a2713aSLionel Sambuc class A { 310f4a2713aSLionel Sambuc A([[gnu::unused]] int a); 311f4a2713aSLionel Sambuc }; 312f4a2713aSLionel Sambuc A::A([[gnu::unused]] int a) {} 313f4a2713aSLionel Sambuc 314f4a2713aSLionel Sambuc namespace GccConst { 315f4a2713aSLionel Sambuc // GCC's tokenizer treats const and __const as the same token. 316f4a2713aSLionel Sambuc [[gnu::const]] int *f1(); 317f4a2713aSLionel Sambuc [[gnu::__const]] int *f2(); 318*0a6a1f1dSLionel Sambuc [[gnu::__const__]] int *f3(); 319f4a2713aSLionel Sambuc void f(const int *); 320f4a2713aSLionel Sambuc void g() { f(f1()); f(f2()); } 321*0a6a1f1dSLionel Sambuc void h() { f(f3()); } 322f4a2713aSLionel Sambuc } 323f4a2713aSLionel Sambuc 324f4a2713aSLionel Sambuc namespace GccASan { 325f4a2713aSLionel Sambuc __attribute__((no_address_safety_analysis)) void f1(); 326f4a2713aSLionel Sambuc __attribute__((no_sanitize_address)) void f2(); 327f4a2713aSLionel Sambuc [[gnu::no_address_safety_analysis]] void f3(); 328f4a2713aSLionel Sambuc [[gnu::no_sanitize_address]] void f4(); 329f4a2713aSLionel Sambuc } 330*0a6a1f1dSLionel Sambuc 331*0a6a1f1dSLionel Sambuc namespace { 332*0a6a1f1dSLionel Sambuc [[deprecated]] void bar(); 333*0a6a1f1dSLionel Sambuc [[deprecated("hello")]] void baz(); 334*0a6a1f1dSLionel Sambuc [[deprecated()]] void foo(); // expected-error {{parentheses must be omitted if 'deprecated' attribute's argument list is empty}} 335*0a6a1f1dSLionel Sambuc [[gnu::deprecated()]] void quux(); 336*0a6a1f1dSLionel Sambuc } 337*0a6a1f1dSLionel Sambuc 338*0a6a1f1dSLionel Sambuc namespace { 339*0a6a1f1dSLionel Sambuc [[ // expected-error {{expected ']'}} 340*0a6a1f1dSLionel Sambuc #pragma pack(pop) 341*0a6a1f1dSLionel Sambuc deprecated 342*0a6a1f1dSLionel Sambuc ]] void bad(); 343*0a6a1f1dSLionel Sambuc } 344