llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Jonas Rembser (guitargeek)

<details>
<summary>Changes</summary>

The enumerators of an unscoped enumeration are in the lookup table of the 
enclosing context. Undoing the input that declared the enumeration removed the 
enumeration from that context, but its enumerators stayed visible:
```
  enum E { Red };
  %undo
  int Red = 5;   // error: redefinition of 'Red' as different kind of symbol
```

Remove the enumerators of an undone enumeration definition, too.

Assisted-by: Claude Opus 5.5

This is another PR that addresses a problem when using Clang-Repl instead of 
Cling in ROOT.

---
Full diff: https://github.com/llvm/llvm-project/pull/228370.diff


2 Files Affected:

- (modified) clang/lib/Interpreter/IncrementalParser.cpp (+6) 
- (modified) clang/test/Interpreter/code-undo.cpp (+18) 


``````````diff
diff --git a/clang/lib/Interpreter/IncrementalParser.cpp 
b/clang/lib/Interpreter/IncrementalParser.cpp
index 3cfabb5e5daa1..85282199dc6e8 100644
--- a/clang/lib/Interpreter/IncrementalParser.cpp
+++ b/clang/lib/Interpreter/IncrementalParser.cpp
@@ -291,6 +291,12 @@ class ASTDeclUnmerger : public 
DeclVisitor<ASTDeclUnmerger> {
   void VisitVarDecl(VarDecl *D) { withdraw(D); }
 
   void VisitTagDecl(TagDecl *D) {
+    // The enumerators of an unscoped enumeration are visible in the enclosing
+    // context.
+    if (auto *ED = dyn_cast<EnumDecl>(D);
+        ED && ED->isThisDeclarationADefinition())
+      VisitDeclContext(ED);
+
     NamedDecl *Prev = findSurvivor(D);
     if (!Prev)
       return;
diff --git a/clang/test/Interpreter/code-undo.cpp 
b/clang/test/Interpreter/code-undo.cpp
index 4516910ca3b4f..a9b88c06d9fdb 100644
--- a/clang/test/Interpreter/code-undo.cpp
+++ b/clang/test/Interpreter/code-undo.cpp
@@ -20,4 +20,22 @@ auto r4 = bar();
 %undo
 auto r5 = bar();
 
+enum E { Red, Green };
+%undo
+int Red = 5;
+auto r6 = printf("Red = %d\n", Red);
+// CHECK-NEXT: Red = 5
+
+enum E { Blue };
+%undo
+enum E { Blue = 7 };
+auto r7 = printf("Blue = %d\n", Blue);
+// CHECK-NEXT: Blue = 7
+
+namespace N { enum F { Yellow = 1 }; }
+%undo
+namespace N { int Yellow = 8; }
+auto r8 = printf("N::Yellow = %d\n", N::Yellow);
+// CHECK-NEXT: N::Yellow = 8
+
 %quit

``````````

</details>


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

Reply via email to