[clang] [clang-repl] Undo the enumerators of an unscoped enumeration (PR #228370)
Jonas Rembser via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 2 02:28:34 PDT 2026
https://github.com/guitargeek created https://github.com/llvm/llvm-project/pull/228370
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.
>From 199d719abbb835eafabd9e1a2855d119ebcbc869 Mon Sep 17 00:00:00 2001
From: Jonas Rembser <jonas.rembser at cern.ch>
Date: Thu, 1 Oct 2026 21:06:53 +0000
Subject: [PATCH] [clang-repl] Undo the enumerators of an unscoped enumeration
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
---
clang/lib/Interpreter/IncrementalParser.cpp | 6 ++++++
clang/test/Interpreter/code-undo.cpp | 18 ++++++++++++++++++
2 files changed, 24 insertions(+)
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
More information about the cfe-commits
mailing list