1 // RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify=expected,notc2x -Wno-strict-prototypes %s
2 // RUN: %clang_cc1 -fsyntax-only -std=gnu2x -verify=expected,c2x %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}}
37 [[]] int; // expected-error {{an attribute list cannot appear here}} \
38 // expected-warning {{declaration does not declare anything}}
41 [[]] struct S2
{ int a
; }; // expected-error {{misplaced attributes}}
42 struct S3
[[]] { int a
; }; // expected-error {{an attribute list cannot appear here}}
49 [[]] union U2
{ double d
; }; // expected-error {{misplaced attributes}}
50 union U3
[[]] { double d
; }; // expected-error {{an attribute list cannot appear here}}
52 struct [[]] IncompleteStruct
;
53 union [[]] IncompleteUnion
;
54 enum [[]] IncompleteEnum
;
55 enum __attribute__((deprecated
)) IncompleteEnum2
;
62 void f5(int i
[[]], [[]] int j
, int [[]] k
);
64 void f6(a
, b
) [[]] int a
; int b
; { // notc2x-error {{an attribute list cannot appear here}} \
65 c2x
-error
{{unknown type name
'a'}} \
66 c2x
-error
{{unknown type name
'b'}} \
67 c2x
-error
{{expected
';' after top level declarator
}} \
68 c2x
-error
{{expected identifier
or '('}}
71 // FIXME: technically, an attribute list cannot appear here, but we currently
72 // parse it as part of the return type of the function, which is reasonable
73 // behavior given that we *don't* want to parse it as part of the K&R parameter
74 // declarations. It is disallowed to avoid a parsing ambiguity we already
76 int (*f7(a
, b
))(int, int) [[]] int a
; int b
; { // c2x-error {{unknown type name 'a'}} \
77 c2x
-error
{{unknown type name
'b'}} \
78 c2x
-error
{{expected
';' after top level declarator
}} \
79 c2x
-error
{{expected identifier
or '('}}
95 int (*fp2
[[]])(void);
100 void f10(int j
[static 10] [[]], int k
[*] [[]]);
107 [[]] case 1: [[]] break;
116 [[]] do [[]] { } while(1);
122 (void)sizeof(int [4][[]]);
123 (void)sizeof(struct [[]] S3
{ int a
[[]]; });
128 [[attr
]] void f12(void); // expected-warning {{unknown attribute 'attr' ignored}}
129 [[vendor::attr
]] void f13(void); // expected-warning {{unknown attribute 'attr' ignored}}
131 // Ensure that asm statements properly handle double colons.
132 void test_asm(void) {
134 asm("foo" :: "r" (xx
)); // expected-error {{use of undeclared identifier 'xx'}}
137 // Do not allow 'using' to introduce vendor attribute namespaces.
138 [[using vendor
: attr1
, attr2
]] void f14(void); // expected-error {{expected ','}} \
139 // expected-warning {{unknown attribute 'using' ignored}}
141 struct [[]] S4
*s
; // expected-error {{an attribute list cannot appear here}}
143 int c
= sizeof(struct [[]] S5
); // expected-error {{an attribute list cannot appear here}}
145 // Ensure that '::' outside of attributes does not crash and is not treated as scope
146 double n::v
; // expected-error {{expected ';' after top level declarator}}