Skip to content

Commit b0e53b1

Browse files
committed
[Clang] handle both gnu and cpp11 attributes to ensure correct parsing inside extern block
1 parent 8949290 commit b0e53b1

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ Bug Fixes to C++ Support
217217
- Clang now preserves the unexpanded flag in a lambda transform used for pack expansion. (#GH56852), (#GH85667),
218218
(#GH99877).
219219
- Fixed a bug when diagnosing ambiguous explicit specializations of constrained member functions.
220+
- Clang now properly handles the order of attributes in `extern` blocks. (#GH101990).
220221

221222
Bug Fixes to AST Handling
222223
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,10 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context) {
425425
[[fallthrough]];
426426
default:
427427
ParsedAttributes DeclAttrs(AttrFactory);
428-
MaybeParseCXX11Attributes(DeclAttrs);
428+
ParsedAttributes DeclSpecAttrs(AttrFactory);
429+
while (MaybeParseCXX11Attributes(DeclAttrs) ||
430+
MaybeParseGNUAttributes(DeclSpecAttrs))
431+
;
429432
ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs);
430433
continue;
431434
}

clang/test/Parser/attr-order.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,11 @@ template <int a>
3131

3232
template <int a>
3333
[[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok
34+
35+
extern "C" {
36+
__attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int l(int); // ok
37+
[[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int m(int); // ok
38+
}
39+
40+
extern "C" __attribute__ ((__warn_unused_result__)) [[__maybe_unused__]] int n(int); // ok
41+
extern "C" [[__maybe_unused__]] __attribute__ ((__warn_unused_result__)) int o(int); // ok

0 commit comments

Comments
 (0)