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; |
| 8 | int array_attr [1] [[]]; |
Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 9 | alignas(8) int aligned_attr; |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 10 | [[test::valid(for 42 [very] **** '+' symbols went on a trip; the end.)]] |
| 11 | int garbage_attr; |
| 12 | void fn_attr () [[]]; |
| 13 | class [[]] class_attr {}; |
| 14 | extern "C++" [[]] int extern_attr; |
| 15 | template <typename T> [[]] void template_attr (); |
Peter Collingbourne | 3497fdf | 2011-09-29 18:04:05 +0000 | [diff] [blame] | 16 | [[]] [[]] int [[]] [[]] multi_attr [[]] [[]]; |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 17 | |
| 18 | int comma_attr [[,]]; // expected-error {{expected identifier}} |
| 19 | int scope_attr [[foo::]]; // expected-error {{expected identifier}} |
Peter Collingbourne | f190768 | 2011-09-29 18:03:57 +0000 | [diff] [blame] | 20 | unsigned [[]] int attr_in_decl_spec; // expected-error {{expected unqualified-id}} |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 21 | int & [[]] ref_attr = after_attr; // expected-error {{an attribute list cannot appear here}} |
| 22 | class foo { |
Eli Friedman | dc3b723 | 2012-01-04 02:40:39 +0000 | [diff] [blame] | 23 | void after_const_attr () const [[]]; // expected-error {{expected body of lambda expression}} |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 24 | }; |
| 25 | extern "C++" [[]] { } // expected-error {{an attribute list cannot appear here}} |
| 26 | [[]] 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^] | 27 | [[]] 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] | 28 | [[]] static_assert(true, ""); //expected-error {{an attribute list cannot appear here}} |
| 29 | [[]] asm(""); // expected-error {{an attribute list cannot appear here}} |
| 30 | |
| 31 | [[]] using ns::i; // expected-error {{an attribute list cannot appear here}} |
| 32 | [[]] using namespace ns; |
| 33 | |
| 34 | // Argument tests |
Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 35 | alignas int aligned_no_params; // expected-error {{expected '('}} |
Richard Smith | 282e7e6 | 2012-02-04 09:53:13 +0000 | [diff] [blame^] | 36 | 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] | 37 | |
| 38 | // Statement tests |
| 39 | void foo () { |
| 40 | [[]] ; |
| 41 | [[]] { } |
| 42 | [[]] if (0) { } |
| 43 | [[]] for (;;); |
| 44 | [[]] do { |
| 45 | [[]] continue; |
| 46 | } while (0); |
| 47 | [[]] while (0); |
| 48 | |
| 49 | [[]] switch (i) { |
| 50 | [[]] case 0: |
| 51 | [[]] default: |
| 52 | [[]] break; |
| 53 | } |
| 54 | |
| 55 | [[]] goto there; |
| 56 | [[]] there: |
| 57 | |
| 58 | [[]] try { |
| 59 | } [[]] catch (...) { // expected-error {{an attribute list cannot appear here}} |
| 60 | } |
| 61 | |
| 62 | [[]] return; |
| 63 | } |