1// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s 2 3// Need std::initializer_list 4namespace std { 5 typedef decltype(sizeof(int)) size_t; 6 7 // libc++'s implementation 8 template <class _E> 9 class initializer_list 10 { 11 const _E* __begin_; 12 size_t __size_; 13 14 initializer_list(const _E* __b, size_t __s) 15 : __begin_(__b), 16 __size_(__s) 17 {} 18 19 public: 20 typedef _E value_type; 21 typedef const _E& reference; 22 typedef const _E& const_reference; 23 typedef size_t size_type; 24 25 typedef const _E* iterator; 26 typedef const _E* const_iterator; 27 28 initializer_list() : __begin_(nullptr), __size_(0) {} 29 30 size_t size() const {return __size_;} 31 const _E* begin() const {return __begin_;} 32 const _E* end() const {return __begin_ + __size_;} 33 }; 34} 35 36 37// Declaration syntax checks 38[[]] int before_attr; 39int [[]] between_attr; 40const [[]] int between_attr_2 = 0; // expected-error {{an attribute list cannot appear here}} 41int after_attr [[]]; 42int * [[]] ptr_attr; 43int & [[]] ref_attr = after_attr; 44int && [[]] rref_attr = 0; 45int array_attr [1] [[]]; 46alignas(8) int aligned_attr; 47[[test::valid(for 42 [very] **** '+' symbols went on a trip and had a "good"_time; the end.)]] 48 int garbage_attr; 49[[,,,static, class, namespace,, inline, constexpr, mutable,, bi\ 50tand, bitor::compl(!.*_ Cx.!U^*R),,,]] int more_garbage_attr; 51[[u8"invalid!"]] int invalid_string_attr; // expected-error {{expected ']'}} 52void fn_attr () [[]]; 53void noexcept_fn_attr () noexcept [[]]; 54struct MemberFnOrder { 55 virtual void f() const volatile && noexcept [[]] final = 0; 56}; 57struct [[]] struct_attr; 58class [[]] class_attr {}; 59union [[]] union_attr; 60[[]] struct with_init_declarators {} init_declarator; 61[[]] struct no_init_declarators; // expected-error {{an attribute list cannot appear here}} 62[[]]; 63struct ctordtor { 64 [[]] ctordtor(); 65 [[]] ~ctordtor(); 66}; 67[[]] ctordtor::ctordtor() {} 68[[]] ctordtor::~ctordtor() {} 69extern "C++" [[]] int extern_attr; 70template <typename T> [[]] void template_attr (); 71[[]] [[]] int [[]] [[]] multi_attr [[]] [[]]; 72 73int comma_attr [[,]]; 74int scope_attr [[foo::]]; // expected-error {{expected identifier}} 75int (paren_attr) [[]]; // expected-error {{an attribute list cannot appear here}} 76unsigned [[]] int attr_in_decl_spec; // expected-error {{an attribute list cannot appear here}} 77unsigned [[]] int [[]] const double_decl_spec = 0; // expected-error 2{{an attribute list cannot appear here}} 78class foo { 79 void const_after_attr () [[]] const; // expected-error {{expected ';'}} 80}; 81extern "C++" [[]] { } // expected-error {{an attribute list cannot appear here}} 82[[]] template <typename T> void before_template_attr (); // expected-error {{an attribute list cannot appear here}} 83[[]] namespace ns { int i; } // expected-error {{an attribute list cannot appear here}} expected-note {{declared here}} 84[[]] static_assert(true, ""); //expected-error {{an attribute list cannot appear here}} 85[[]] asm(""); // expected-error {{an attribute list cannot appear here}} 86 87[[]] using ns::i; // expected-error {{an attribute list cannot appear here}} 88[[]] using namespace ns; 89 90[[]] using T = int; // expected-error {{an attribute list cannot appear here}} 91using T [[]] = int; // ok 92template<typename T> using U [[]] = T; 93using ns::i [[]]; // expected-error {{an attribute list cannot appear here}} 94using [[]] ns::i; // expected-error {{an attribute list cannot appear here}} 95 96auto trailing() -> [[]] const int; // expected-error {{an attribute list cannot appear here}} 97auto trailing() -> const [[]] int; // expected-error {{an attribute list cannot appear here}} 98auto trailing() -> const int [[]]; 99auto trailing_2() -> struct struct_attr [[]]; 100 101namespace N { 102 struct S {}; 103}; 104template<typename> struct Template {}; 105 106// FIXME: Improve this diagnostic 107struct [[]] N::S s; // expected-error {{an attribute list cannot appear here}} 108struct [[]] Template<int> t; // expected-error {{an attribute list cannot appear here}} 109struct [[]] ::template Template<int> u; // expected-error {{an attribute list cannot appear here}} 110template struct [[]] Template<char>; // expected-error {{an attribute list cannot appear here}} 111template <> struct [[]] Template<void>; 112 113enum [[]] E1 {}; 114enum [[]] E2; // expected-error {{forbids forward references}} 115enum [[]] E1; 116enum [[]] E3 : int; 117enum [[]] { 118 k_123 [[]] = 123 // expected-error {{an attribute list cannot appear here}} 119}; 120enum [[]] E1 e; // expected-error {{an attribute list cannot appear here}} 121enum [[]] class E4 { }; // expected-error {{an attribute list cannot appear here}} 122enum struct [[]] E5; 123 124struct S { 125 friend int f [[]] (); // expected-FIXME{{an attribute list cannot appear here}} 126 [[]] friend int g(); // expected-FIXME{{an attribute list cannot appear here}} 127 [[]] friend int h() { 128 } 129 friend class [[]] C; // expected-error{{an attribute list cannot appear here}} 130}; 131template<typename T> void tmpl(T) {} 132template void tmpl [[]] (int); // expected-FIXME {{an attribute list cannot appear here}} 133template [[]] void tmpl(char); // expected-error {{an attribute list cannot appear here}} 134template void [[]] tmpl(short); 135 136// Argument tests 137alignas int aligned_no_params; // expected-error {{expected '('}} 138alignas(i) int aligned_nonconst; // expected-error {{'aligned' attribute requires integer constant}} expected-note {{read of non-const variable 'i'}} 139 140// Statement tests 141void foo () { 142 [[]] ; 143 [[]] { } 144 [[]] if (0) { } 145 [[]] for (;;); 146 [[]] do { 147 [[]] continue; 148 } while (0); 149 [[]] while (0); 150 151 [[]] switch (i) { 152 [[]] case 0: 153 [[]] default: 154 [[]] break; 155 } 156 157 [[]] goto there; 158 [[]] there: 159 160 [[]] try { 161 } [[]] catch (...) { // expected-error {{an attribute list cannot appear here}} 162 } 163 struct S { int arr[2]; } s; 164 (void)s.arr[ [] { return 0; }() ]; // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}} 165 int n = __builtin_offsetof(S, arr[ [] { return 0; }() ]); // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}} 166 167 void bar [[noreturn]] ([[]] int i, [[]] int j); 168 using FuncType = void ([[]] int); 169 void baz([[]]...); // expected-error {{expected parameter declarator}} 170 171 [[]] return; 172} 173 174template<typename...Ts> void variadic() { 175 void bar [[noreturn...]] (); // expected-error {{attribute 'noreturn' cannot be used as an attribute pack}} 176} 177 178// Expression tests 179void bar () { 180 [] () [[noreturn]] { return; } (); // expected-error {{should not return}} 181 [] () [[noreturn]] { throw; } (); 182 new int[42][[]][5][[]]{}; 183} 184 185// Condition tests 186void baz () { 187 if ([[]] bool b = true) { 188 switch ([[]] int n { 42 }) { 189 default: 190 for ([[]] int n = 0; [[]] char b = n < 5; ++b) { 191 } 192 } 193 } 194 int x; 195 // An attribute can be applied to an expression-statement, such as the first 196 // statement in a for. But it can't be applied to a condition which is an 197 // expression. 198 for ([[]] x = 0; ; ) {} // expected-error {{an attribute list cannot appear here}} 199 for (; [[]] x < 5; ) {} // expected-error {{an attribute list cannot appear here}} 200 while ([[]] bool k { false }) { 201 } 202 while ([[]] true) { // expected-error {{an attribute list cannot appear here}} 203 } 204 do { 205 } while ([[]] false); // expected-error {{an attribute list cannot appear here}} 206 207 for ([[]] int n : { 1, 2, 3 }) { 208 } 209} 210 211enum class __attribute__((visibility("hidden"))) SecretKeepers { 212 one, /* rest are deprecated */ two, three 213}; 214enum class [[]] EvenMoreSecrets {}; 215