[PATCH] D99338: [clang][parser] Allow GNU-style attributes in enum specifiers

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 25 07:06:26 PDT 2021


tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, rsmith.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We are parsing both C++11 and GNU-style attributes here, but the previous `ProhibitAttributes()` call was never working for GNU-style attributes.

GNU-style attributes are however expected to be parsed and not diagnosed, for example in `clang/test/Sema/ast-print` in the following code:

  // CHECK-LABEL: enum __attribute__((deprecated(""))) EnumWithAttributes2 *EnumWithAttributes2Ptr;
  // expected-warning at +2 {{'EnumWithAttributes2' is deprecated}}
  // expected-note at +1 {{'EnumWithAttributes2' has been explicitly marked deprecated here}}
  enum __attribute__((deprecated)) EnumWithAttributes2 *EnumWithAttributes2Ptr;

This is essentially the same as https://reviews.llvm.org/D99278 and needs https://reviews.llvm.org/D97362 to be applied first.

The comment just above this change is a bit confusing since it tries to explain that "an elaborated-type-specifier has a much more constrained grammar", but does not mention any attributes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99338

Files:
  clang/lib/Parse/ParseDecl.cpp


Index: clang/lib/Parse/ParseDecl.cpp
===================================================================
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -4653,7 +4653,7 @@
   // or opaque-enum-declaration anywhere.
   if (IsElaboratedTypeSpecifier && !getLangOpts().MicrosoftExt &&
       !getLangOpts().ObjC) {
-    ProhibitAttributes(attrs);
+    ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed, /*DiagnoseEmptyAttrs=*/true);
     if (BaseType.isUsable())
       Diag(BaseRange.getBegin(), diag::ext_enum_base_in_type_specifier)
           << (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes) << BaseRange;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99338.333293.patch
Type: text/x-patch
Size: 649 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210325/155f9002/attachment.bin>


More information about the cfe-commits mailing list