Richard Smith | 762bb9d | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2 | |
| 3 | // Declaration syntax checks |
| 4 | [[]] int before_attr; |
Peter Collingbourne | f190768 | 2011-09-29 18:03:57 +0000 | [diff] [blame] | 5 | int [[]] between_attr; |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 6 | int after_attr [[]]; |
| 7 | int * [[]] ptr_attr; |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 8 | int & [[]] ref_attr = after_attr; |
| 9 | int && [[]] rref_attr = 0; |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 10 | int array_attr [1] [[]]; |
Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 11 | alignas(8) int aligned_attr; |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 12 | [[test::valid(for 42 [very] **** '+' symbols went on a trip; the end.)]] |
| 13 | int garbage_attr; |
Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame^] | 14 | [[,,,static, class, namespace,, inline, constexpr, mutable,, bi\ |
| 15 | tand, bitor::compl(!.*_ Cx.!U^*R),,,]] int more_garbage_attr; |
| 16 | [[u8"invalid!"]] int invalid_string_attr; // expected-error {{expected ']'}} |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 17 | void fn_attr () [[]]; |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 18 | void noexcept_fn_attr () noexcept [[]]; |
| 19 | struct MemberFnOrder { |
| 20 | virtual void f() const volatile && noexcept [[]] final = 0; |
| 21 | }; |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 22 | class [[]] class_attr {}; |
| 23 | extern "C++" [[]] int extern_attr; |
| 24 | template <typename T> [[]] void template_attr (); |
Peter Collingbourne | 3497fdf | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 25 | [[]] [[]] int [[]] [[]] multi_attr [[]] [[]]; |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 26 | |
Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame^] | 27 | int comma_attr [[,]]; |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 28 | int scope_attr [[foo::]]; // expected-error {{expected identifier}} |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 29 | int (paren_attr) [[]]; // expected-error {{an attribute list cannot appear here}} |
Peter Collingbourne | f190768 | 2011-09-29 18:03:57 +0000 | [diff] [blame] | 30 | unsigned [[]] int attr_in_decl_spec; // expected-error {{expected unqualified-id}} |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 31 | class foo { |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 32 | void const_after_attr () [[]] const; // expected-error {{expected ';'}} |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 33 | }; |
| 34 | extern "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}} |
Richard Smith | 282e7e6 | 2012-02-04 09:53:13 +0000 | [diff] [blame] | 36 | [[]] namespace ns { int i; } // expected-error {{an attribute list cannot appear here}} expected-note {{declared here}} |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 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 |
Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 44 | alignas int aligned_no_params; // expected-error {{expected '('}} |
Richard Smith | 282e7e6 | 2012-02-04 09:53:13 +0000 | [diff] [blame] | 45 | alignas(i) int aligned_nonconst; // expected-error {{'aligned' attribute requires integer constant}} expected-note {{read of non-const variable 'i'}} |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 46 | |
| 47 | // Statement tests |
| 48 | void 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 | } |
Richard Smith | 6ee326a | 2012-04-10 01:32:12 +0000 | [diff] [blame] | 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 | |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 74 | [[]] return; |
| 75 | } |
Richard Smith | c56298d | 2012-04-10 03:25:07 +0000 | [diff] [blame^] | 76 | |
| 77 | template<typename...Ts> void variadic() { |
| 78 | void bar [[noreturn...]] (); // expected-error {{attribute 'noreturn' cannot be used as an attribute pack}} |
| 79 | } |