1 // RUN: %clang_cc1 -fsyntax-only -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 string literal as argument of 'deprecated' attribute}}
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}}
28 [[deprecated(L
"abc")]] void unevaluated_string(void);
29 // expected-warning@-1 {{encoding prefix 'L' on an unevaluated string literal has no effect}}
31 [[nodiscard("\123")]] int unevaluated_string2(void);
32 // expected-error@-1 {{invalid escape sequence '\123' in an unevaluated string literal}}
41 int [[]] : 0; // OK, attribute applies to the type.
42 int p
, [[]] : 0; // expected-error {{an attribute list cannot appear here}}
43 int q
, [[]] r
; // expected-error {{an attribute list cannot appear here}}
44 [[]] int; // expected-error {{an attribute list cannot appear here}} \
45 // expected-warning {{declaration does not declare anything}}
48 [[]] struct S2
{ int a
; }; // expected-error {{misplaced attributes}}
49 struct S3
[[]] { int a
; }; // expected-error {{an attribute list cannot appear here}}
56 [[]] union U2
{ double d
; }; // expected-error {{misplaced attributes}}
57 union U3
[[]] { double d
; }; // expected-error {{an attribute list cannot appear here}}
59 struct [[]] IncompleteStruct
;
60 union [[]] IncompleteUnion
;
61 enum [[]] IncompleteEnum
;
62 enum __attribute__((deprecated
)) IncompleteEnum2
;
69 void f5(int i
[[]], [[]] int j
, int [[]] k
);
71 void f6(a
, b
) [[]] int a
; int b
; { // notc2x-error {{an attribute list cannot appear here}} \
72 c2x
-error
{{unknown type name
'a'}} \
73 c2x
-error
{{unknown type name
'b'}} \
74 c2x
-error
{{expected
';' after top level declarator
}} \
75 c2x
-error
{{expected identifier
or '('}}
78 // FIXME: technically, an attribute list cannot appear here, but we currently
79 // parse it as part of the return type of the function, which is reasonable
80 // behavior given that we *don't* want to parse it as part of the K&R parameter
81 // declarations. It is disallowed to avoid a parsing ambiguity we already
83 int (*f7(a
, b
))(int, int) [[]] int a
; int b
; { // c2x-error {{unknown type name 'a'}} \
84 c2x
-error
{{unknown type name
'b'}} \
85 c2x
-error
{{expected
';' after top level declarator
}} \
86 c2x
-error
{{expected identifier
or '('}}
101 int (*fp1
)(void)[[]];
102 int (*fp2
[[]])(void);
107 void f10(int j
[static 10] [[]], int k
[*] [[]]);
114 [[]] case 1: [[]] break;
123 [[]] do [[]] { } while(1);
129 (void)sizeof(int [4][[]]);
130 (void)sizeof(struct [[]] S3
{ int a
[[]]; });
135 [[attr
]] void f12(void); // expected-warning {{unknown attribute 'attr' ignored}}
136 [[vendor::attr
]] void f13(void); // expected-warning {{unknown attribute 'attr' ignored}}
138 // Ensure that asm statements properly handle double colons.
139 void test_asm(void) {
141 asm("foo" :: "r" (xx
)); // expected-error {{use of undeclared identifier 'xx'}}
144 // Do not allow 'using' to introduce vendor attribute namespaces.
145 [[using vendor
: attr1
, attr2
]] void f14(void); // expected-error {{expected ','}} \
146 // expected-warning {{unknown attribute 'using' ignored}}
148 struct [[]] S4
*s
; // expected-error {{an attribute list cannot appear here}}
150 int c
= sizeof(struct [[]] S5
); // expected-error {{an attribute list cannot appear here}}
152 // Ensure that '::' outside of attributes does not crash and is not treated as scope
153 double n::v
; // expected-error {{expected ';' after top level declarator}}