[PATCH] D147989: [clang] Fix Attribute Placement

Priyanshi Agarwal via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 10 23:08:18 PDT 2023


ipriyanshi1708 updated this revision to Diff 512344.
ipriyanshi1708 retitled this revision from "Fix Attribute Placememt" to "[clang] Fix Attribute Placement".
ipriyanshi1708 added a comment.

Updated the title


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147989/new/

https://reviews.llvm.org/D147989

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Sema/SemaDecl.cpp


Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -55,7 +55,7 @@
 
 using namespace clang;
 using namespace sema;
-
+bool isEnumClass = false;
 Sema::DeclGroupPtrTy Sema::ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType) {
   if (OwnedType) {
     Decl *Group[2] = { OwnedType, Ptr };
@@ -5028,6 +5028,9 @@
 }
 
 static unsigned GetDiagnosticTypeSpecifierID(DeclSpec::TST T) {
+  if (isEnumClass) {
+    return 5;
+  }else{
   switch (T) {
   case DeclSpec::TST_class:
     return 0;
@@ -5042,6 +5045,7 @@
   default:
     llvm_unreachable("unexpected type specifier");
   }
+  }
 }
 
 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
@@ -5298,13 +5302,19 @@
         TypeSpecType == DeclSpec::TST_interface ||
         TypeSpecType == DeclSpec::TST_union ||
         TypeSpecType == DeclSpec::TST_enum) {
+           if (TypeSpecType == DeclSpec::TST_enum) {
+        if (const EnumDecl *ED = dyn_cast<EnumDecl>(DS.getRepAsDecl())) {
+          if (ED->isScopedUsingClassTag())
+            isEnumClass = true;
+        }
+      }
       for (const ParsedAttr &AL : DS.getAttributes())
         Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
             << AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
       for (const ParsedAttr &AL : DeclAttrs)
         Diag(AL.getLoc(), diag::warn_declspec_attribute_ignored)
             << AL << GetDiagnosticTypeSpecifierID(TypeSpecType);
-    }
+        }
   }
 
   return TagD;
Index: clang/include/clang/Sema/DeclSpec.h
===================================================================
--- clang/include/clang/Sema/DeclSpec.h
+++ clang/include/clang/Sema/DeclSpec.h
@@ -271,7 +271,6 @@
     TSC_imaginary,
     TSC_complex
   };
-
   // Import type specifier type enumeration and constants.
   typedef TypeSpecifierType TST;
   static const TST TST_unspecified = clang::TST_unspecified;
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3421,7 +3421,7 @@
   InGroup<DeprecatedAttributes>;
 def warn_declspec_attribute_ignored : Warning<
   "attribute %0 is ignored, place it after "
-  "\"%select{class|struct|interface|union|enum}1\" to apply attribute to "
+  "\"%select{class|struct|interface|union|enum|enum class}1\" to apply attribute to "
   "type declaration">, InGroup<IgnoredAttributes>;
 def warn_attribute_precede_definition : Warning<
   "attribute declaration must precede definition">,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147989.512344.patch
Type: text/x-patch
Size: 2697 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230411/1861e8ed/attachment-0001.bin>


More information about the cfe-commits mailing list