[clang] [clang-repl] Restore the lookup of out-of-line definitions' predecessors (PR #229780)
Jonas Rembser via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 7 02:56:55 PST 2026
================
@@ -284,13 +274,48 @@ class ASTDeclUnmerger : public DeclVisitor<ASTDeclUnmerger> {
VisitDeclContext(DC);
}
- void VisitFunctionDecl(FunctionDecl *D) { withdraw(D); }
- void VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { withdraw(D); }
- void VisitTypedefNameDecl(TypedefNameDecl *D) { withdraw(D); }
- void VisitUsingShadowDecl(UsingShadowDecl *D) { withdraw(D); }
- void VisitVarDecl(VarDecl *D) { withdraw(D); }
+ /// Remove ND from its context and the lookup tables, and make the
+ /// declaration it redeclares visible again. Called before the
+ /// redeclaration chain of ND is restored, which hides that declaration.
+ void VisitNamedDecl(NamedDecl *ND) {
+ // The templated decl of a template is not a member of its context: the
+ // template is.
+ DeclContext *DC = ND->getLexicalDeclContext();
+ if (!DC->containsDecl(ND))
+ return;
+ NamedDecl *Prev = findSurvivor(ND);
+ DC->removeDecl(ND);
+ removeFromLookups(ND);
+ // Like removeDecl(), use the semantic context: the out-of-line definition
+ // of a member is in DC, but it was removed from the lookup table of its
+ // class or namespace.
+ if (Prev)
+ Prev->getDeclContext()->makeDeclVisibleInContext(Prev);
+ }
+
+ void VisitFunctionDecl(FunctionDecl *D) {
+ VisitNamedDecl(D);
+ withdraw(D);
+ }
+ void VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
+ VisitNamedDecl(D);
+ withdraw(D);
+ }
+ void VisitTypedefNameDecl(TypedefNameDecl *D) {
+ VisitNamedDecl(D);
+ withdraw(D);
+ }
+ void VisitUsingShadowDecl(UsingShadowDecl *D) {
+ VisitNamedDecl(D);
+ withdraw(D);
+ }
+ void VisitVarDecl(VarDecl *D) {
+ VisitNamedDecl(D);
+ withdraw(D);
+ }
----------------
guitargeek wrote:
Done in the latest push from last month (sorry that I didn't post a comment to go with it): `withdraw()` is gone, and all the redeclarable visitors (including `VisitTagDecl`, `VisitRedeclarableTemplateDecl` and `VisitNamespaceDecl`) now go through a single `VisitRedeclarable()`.
The per-type visitors are still there as one-line forwarders, because `DeclVisitor` can't dispatch to `VisitRedeclarable` on its own: `Redeclarable<T>` is a mixin, not a node in `DeclNodes.td`. This follows the same pattern as `ASTDeclReader`, where each `VisitXDecl` calls `VisitRedeclarable` explicitly. If you had a way in mind to drop the forwarders entirely, I'm happy to change it.
https://github.com/llvm/llvm-project/pull/229780
More information about the cfe-commits
mailing list