[clang] [clang] improve suggested attribute location for scoped enums (PR #124122)

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 23 08:34:07 PST 2025


================
@@ -1175,12 +1175,21 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal(
       }
 
     };
-    // Suggest correct location to fix '[[attrib]] struct' to 'struct [[attrib]]'
+    // Suggest correct location to fix '[[attrib]] struct' to 'struct [[attrib]]'...
     SourceLocation CorrectLocationForAttributes =
         DeclSpec::isDeclRep(DS.getTypeSpecType())
             ? DS.getTypeSpecTypeLoc().getLocWithOffset(
                   LengthOfTSTToken(DS.getTypeSpecType()))
             : SourceLocation();
+    // ... suggested location should be after 'class/struct' for scoped enums
+    if (DS.getTypeSpecType() == DeclSpec::TST_enum) {
+      const EnumDecl *ED = cast<EnumDecl>(DS.getRepAsDecl());
+      if (ED->isScoped()) {
+        // FIXME: offset is dependent on number of spaces after 'enum'
+        CorrectLocationForAttributes =
+            CorrectLocationForAttributes.getLocWithOffset(6);
----------------
Fznamznon wrote:

Yeah, I don't think that is a robust solution, we probably need to figure a dynamic way to get the correct location.

https://github.com/llvm/llvm-project/pull/124122


More information about the cfe-commits mailing list