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