cxx0x-attributes.cpp revision c56298d87a9df507805a548d7d515e8b511df2c0
1// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s 2 3// Declaration syntax checks 4[[]] int before_attr; 5int [[]] between_attr; 6int after_attr [[]]; 7int * [[]] ptr_attr; 8int & [[]] ref_attr = after_attr; 9int && [[]] rref_attr = 0; 10int array_attr [1] [[]]; 11alignas(8) int aligned_attr; 12[[test::valid(for 42 [very] **** '+' symbols went on a trip; the end.)]] 13 int garbage_attr; 14[[,,,static, class, namespace,, inline, constexpr, mutable,, bi\ 15tand, bitor::compl(!.*_ Cx.!U^*R),,,]] int more_garbage_attr; 16[[u8"invalid!"]] int invalid_string_attr; // expected-error {{expected ']'}} 17void fn_attr () [[]]; 18void noexcept_fn_attr () noexcept [[]]; 19struct MemberFnOrder { 20 virtual void f() const volatile && noexcept [[]] final = 0; 21}; 22class [[]] class_attr {}; 23extern "C++" [[]] int extern_attr; 24template <typename T> [[]] void template_attr (); 25[[]] [[]] int [[]] [[]] multi_attr [[]] [[]]; 26 27int comma_attr [[,]]; 28int scope_attr [[foo::]]; // expected-error {{expected identifier}} 29int (paren_attr) [[]]; // expected-error {{an attribute list cannot appear here}} 30unsigned [[]] int attr_in_decl_spec; // expected-error {{expected unqualified-id}} 31class foo { 32 void const_after_attr () [[]] const; // expected-error {{expected ';'}} 33}; 34extern "C++" [[]] { } // expected-error {{an attribute list cannot appear here}} 35[[]] template <typename T> void before_template_attr (); // expected-error {{an attribute list cannot appear here}} 36[[]] namespace ns { int i; } // expected-error {{an attribute list cannot appear here}} expected-note {{declared here}} 37[[]] static_assert(true, ""); //expected-error {{an attribute list cannot appear here}} 38[[]] asm(""); // expected-error {{an attribute list cannot appear here}} 39 40[[]] using ns::i; // expected-error {{an attribute list cannot appear here}} 41[[]] using namespace ns; 42 43// Argument tests 44alignas int aligned_no_params; // expected-error {{expected '('}} 45alignas(i) int aligned_nonconst; // expected-error {{'aligned' attribute requires integer constant}} expected-note {{read of non-const variable 'i'}} 46 47// Statement tests 48void foo () { 49 [[]] ; 50 [[]] { } 51 [[]] if (0) { } 52 [[]] for (;;); 53 [[]] do { 54 [[]] continue; 55 } while (0); 56 [[]] while (0); 57 58 [[]] switch (i) { 59 [[]] case 0: 60 [[]] default: 61 [[]] break; 62 } 63 64 [[]] goto there; 65 [[]] there: 66 67 [[]] try { 68 } [[]] catch (...) { // expected-error {{an attribute list cannot appear here}} 69 } 70 struct S { int arr[2]; } s; 71 (void)s.arr[ [] { return 0; }() ]; // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}} 72 int n = __builtin_offsetof(S, arr[ [] { return 0; }() ]); // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}} 73 74 [[]] return; 75} 76 77template<typename...Ts> void variadic() { 78 void bar [[noreturn...]] (); // expected-error {{attribute 'noreturn' cannot be used as an attribute pack}} 79} 80