================
@@ -1100,30 +1100,32 @@ Parser::DeclGroupPtrTy 
Parser::ParseDeclOrFunctionDefInternal(
   // C99 6.7.2.3p6: Handle "struct-or-union identifier;", "enum { X };"
   // declaration-specifiers init-declarator-list[opt] ';'
   if (Tok.is(tok::semi)) {
-    auto LengthOfTSTToken = [](DeclSpec::TST TKind) {
-      assert(DeclSpec::isDeclRep(TKind));
-      switch(TKind) {
-      case DeclSpec::TST_class:
-        return 5;
-      case DeclSpec::TST_struct:
-        return 6;
-      case DeclSpec::TST_union:
-        return 5;
-      case DeclSpec::TST_enum:
-        return 4;
-      case DeclSpec::TST_interface:
-        return 9;
-      default:
-        llvm_unreachable("we only expect to get the length of the 
class/struct/union/enum");
+    auto GetAdjustedAttrsLoc = [&]() {
+      auto TKind = DS.getTypeSpecType();
+      if (!DeclSpec::isDeclRep(TKind))
+        return SourceLocation();
+
+      if (TKind == DeclSpec::TST_enum) {
----------------
AaronBallman wrote:

My reading of the [grammar](https://eel.is/c++draft/enum) is that the attribute 
can go after the key (so either `enum` or `enum class|struct`), which I think 
is easier to reason about than what it can go *before*.

Because "before" means more logic; there could be an optional nested name 
specifier. e.g., https://godbolt.org/z/eMo5T8r53 or there could be no name but 
an enum base, e.g., https://godbolt.org/z/jbqjnrn3d and so on.

So I think what makes the most sense is for `EnumDecl` to track a source range 
for the enum key. So it'll either be a single token (`enum`) or it will be all 
of the tokens in the key (`enum class`). Then we can use the end of that range. 
Then the logic works regardless of whether the enum is scoped or not.

WDYT?



https://github.com/llvm/llvm-project/pull/168092
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to