[clang] [clang][ASTImporter] Improve import of friend class templates. (PR #74627)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 9 04:22:04 PST 2024
=?utf-8?q?Balázs_Kéri?= <balazs.keri at ericsson.com>,
=?utf-8?q?Balázs_Kéri?= <balazs.keri at ericsson.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/74627 at github.com>
================
@@ -5919,15 +5919,26 @@ ExpectedDecl ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
if (ToD)
return ToD;
- bool IsFriendTemplate = D->getFriendObjectKind() != Decl::FOK_None;
- bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
- : DC->isDependentContext();
- bool DependentFriend = IsFriendTemplate && IsDependentContext;
+ // Should check if a declaration is friend in a dependent context.
+ // Such templates are not linked together in a declaration chain.
+ // The ASTImporter strategy is to map existing forward declarations to
+ // imported ones only if strictly necessary, otherwise import these as new
+ // forward declarations. In case of the "dependent friend" declarations, new
+ // declarations are created, but not linked in a declaration chain.
+ auto IsDependentFriend = [](ClassTemplateDecl *TD) {
+ bool IsFriendTemplate = TD->getFriendObjectKind() != Decl::FOK_None;
+ DeclContext *DC = TD->getDeclContext();
+ DeclContext *LexicalDC = TD->getLexicalDeclContext();
+ bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
+ : DC->isDependentContext();
----------------
NagyDonat wrote:
```suggestion
bool IsDependentContext = TD->getLexicalDeclContext()->isDependentContext();
```
The ternary operator (that you inherited from old code) is superfluous, because if `DC != LexicalDC` is false, then the two branches are identical.
(By the way, is the logic correct? Perhaps the original author intended to have a difference between the branches...)
https://github.com/llvm/llvm-project/pull/74627
More information about the cfe-commits
mailing list