1 // RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -std=gnu2x -verify %s
11 [[]] enum E2
{ Five
}; // expected-error {{misplaced attributes}}
13 // FIXME: this diagnostic can be improved.
14 enum { [[]] Six
}; // expected-error {{expected identifier}}
16 // FIXME: this diagnostic can be improved.
17 enum E3
[[]] { Seven
}; // expected-error {{expected identifier or '('}}
19 [[deprecated([""])]] int WrongArgs
; // expected-error {{expected expression}}
20 [[,,,,,]] int Commas1
; // ok
21 [[,, maybe_unused
]] int Commas2
; // ok
22 [[maybe_unused
,,,]] int Commas3
; // ok
23 [[,,maybe_unused
,]] int Commas4
; // ok
24 [[foo bar
]] int NoComma
; // expected-error {{expected ','}} \
25 // expected-warning {{unknown attribute 'foo' ignored}}
34 int [[]] : 0; // OK, attribute applies to the type.
35 int p
, [[]] : 0; // expected-error {{an attribute list cannot appear here}}
36 int q
, [[]] r
; // expected-error {{an attribute list cannot appear here}}
39 [[]] struct S2
{ int a
; }; // expected-error {{misplaced attributes}}
40 struct S3
[[]] { int a
; }; // expected-error {{an attribute list cannot appear here}}
47 [[]] union U2
{ double d
; }; // expected-error {{misplaced attributes}}
48 union U3
[[]] { double d
; }; // expected-error {{an attribute list cannot appear here}}
50 struct [[]] IncompleteStruct
;
51 union [[]] IncompleteUnion
;
52 enum [[]] IncompleteEnum
;
53 enum __attribute__((deprecated
)) IncompleteEnum2
;
60 void f5(int i
[[]], [[]] int j
, int [[]] k
);
62 void f6(a
, b
) [[]] int a
; int b
; { // expected-error {{an attribute list cannot appear here}}
65 // FIXME: technically, an attribute list cannot appear here, but we currently
66 // parse it as part of the return type of the function, which is reasonable
67 // behavior given that we *don't* want to parse it as part of the K&R parameter
68 // declarations. It is disallowed to avoid a parsing ambiguity we already
70 int (*f7(a
, b
))(int, int) [[]] int a
; int b
; {
85 int (*fp2
[[]])(void);
90 void f10(int j
[static 10] [[]], int k
[*] [[]]);
97 [[]] case 1: [[]] break;
106 [[]] do [[]] { } while(1);
112 (void)sizeof(int [4][[]]);
113 (void)sizeof(struct [[]] S3
{ int a
[[]]; });
118 [[attr
]] void f12(void); // expected-warning {{unknown attribute 'attr' ignored}}
119 [[vendor::attr
]] void f13(void); // expected-warning {{unknown attribute 'attr' ignored}}
121 // Ensure that asm statements properly handle double colons.
122 void test_asm(void) {
124 asm("foo" :: "r" (xx
)); // expected-error {{use of undeclared identifier 'xx'}}
127 // Do not allow 'using' to introduce vendor attribute namespaces.
128 [[using vendor
: attr1
, attr2
]] void f14(void); // expected-error {{expected ','}} \
129 // expected-warning {{unknown attribute 'using' ignored}}
131 struct [[]] S4
*s
; // expected-error {{an attribute list cannot appear here}}
133 int c
= sizeof(struct [[]] S5
); // expected-error {{an attribute list cannot appear here}}