blob: b20873509b6d717a1dd5e97696be3a99f0494b7d [file] [log] [blame]
Richard Smith762bb9d2011-10-13 22:29:44 +00001// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s
Sean Huntbbd37c62009-11-21 08:43:09 +00002
3// Declaration syntax checks
4[[]] int before_attr;
Peter Collingbournef1907682011-09-29 18:03:57 +00005int [[]] between_attr;
Sean Huntbbd37c62009-11-21 08:43:09 +00006int after_attr [[]];
7int * [[]] ptr_attr;
Richard Smith6ee326a2012-04-10 01:32:12 +00008int & [[]] ref_attr = after_attr;
9int && [[]] rref_attr = 0;
Sean Huntbbd37c62009-11-21 08:43:09 +000010int array_attr [1] [[]];
Peter Collingbourne82d0b0a2011-09-29 18:04:28 +000011alignas(8) int aligned_attr;
Sean Huntbbd37c62009-11-21 08:43:09 +000012[[test::valid(for 42 [very] **** '+' symbols went on a trip; the end.)]]
13 int garbage_attr;
14void fn_attr () [[]];
Richard Smith6ee326a2012-04-10 01:32:12 +000015void noexcept_fn_attr () noexcept [[]];
16struct MemberFnOrder {
17 virtual void f() const volatile && noexcept [[]] final = 0;
18};
Sean Huntbbd37c62009-11-21 08:43:09 +000019class [[]] class_attr {};
20extern "C++" [[]] int extern_attr;
21template <typename T> [[]] void template_attr ();
Peter Collingbourne3497fdf2011-09-29 18:04:05 +000022[[]] [[]] int [[]] [[]] multi_attr [[]] [[]];
Sean Huntbbd37c62009-11-21 08:43:09 +000023
24int comma_attr [[,]]; // expected-error {{expected identifier}}
25int scope_attr [[foo::]]; // expected-error {{expected identifier}}
Richard Smith6ee326a2012-04-10 01:32:12 +000026int (paren_attr) [[]]; // expected-error {{an attribute list cannot appear here}}
Peter Collingbournef1907682011-09-29 18:03:57 +000027unsigned [[]] int attr_in_decl_spec; // expected-error {{expected unqualified-id}}
Sean Huntbbd37c62009-11-21 08:43:09 +000028class foo {
Richard Smith6ee326a2012-04-10 01:32:12 +000029 void const_after_attr () [[]] const; // expected-error {{expected ';'}}
Sean Huntbbd37c62009-11-21 08:43:09 +000030};
31extern "C++" [[]] { } // expected-error {{an attribute list cannot appear here}}
32[[]] template <typename T> void before_template_attr (); // expected-error {{an attribute list cannot appear here}}
Richard Smith282e7e62012-02-04 09:53:13 +000033[[]] namespace ns { int i; } // expected-error {{an attribute list cannot appear here}} expected-note {{declared here}}
Sean Huntbbd37c62009-11-21 08:43:09 +000034[[]] static_assert(true, ""); //expected-error {{an attribute list cannot appear here}}
35[[]] asm(""); // expected-error {{an attribute list cannot appear here}}
36
37[[]] using ns::i; // expected-error {{an attribute list cannot appear here}}
38[[]] using namespace ns;
39
40// Argument tests
Peter Collingbourne82d0b0a2011-09-29 18:04:28 +000041alignas int aligned_no_params; // expected-error {{expected '('}}
Richard Smith282e7e62012-02-04 09:53:13 +000042alignas(i) int aligned_nonconst; // expected-error {{'aligned' attribute requires integer constant}} expected-note {{read of non-const variable 'i'}}
Sean Huntbbd37c62009-11-21 08:43:09 +000043
44// Statement tests
45void foo () {
46 [[]] ;
47 [[]] { }
48 [[]] if (0) { }
49 [[]] for (;;);
50 [[]] do {
51 [[]] continue;
52 } while (0);
53 [[]] while (0);
54
55 [[]] switch (i) {
56 [[]] case 0:
57 [[]] default:
58 [[]] break;
59 }
60
61 [[]] goto there;
62 [[]] there:
63
64 [[]] try {
65 } [[]] catch (...) { // expected-error {{an attribute list cannot appear here}}
66 }
Richard Smith6ee326a2012-04-10 01:32:12 +000067 struct S { int arr[2]; } s;
68 (void)s.arr[ [] { return 0; }() ]; // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}}
69 int n = __builtin_offsetof(S, arr[ [] { return 0; }() ]); // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}}
70
Sean Huntbbd37c62009-11-21 08:43:09 +000071 [[]] return;
72}