aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Serialization/ASTWriter.cpp
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2025-09-18 13:34:41 +0800
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>2025-09-18 13:44:21 +0800
commitac2b51e6ce157b430b3823ebc90def9f1d49d36e (patch)
treeaea0f593cfa5b867130e85894034bcf37ba95e22 /clang/lib/Serialization/ASTWriter.cpp
parent4663d2521c65827ca22884e12a96ddd437377e31 (diff)
downloadllvm-ac2b51e6ce157b430b3823ebc90def9f1d49d36e.zip
llvm-ac2b51e6ce157b430b3823ebc90def9f1d49d36e.tar.gz
llvm-ac2b51e6ce157b430b3823ebc90def9f1d49d36e.tar.bz2
[C++20] [Modules] Fix issues with non-exported in-class friend declarations
Close https://github.com/llvm/llvm-project/issues/159424 Close https://github.com/llvm/llvm-project/issues/133720 For in-class friend declaration, it is hard for the serializer to decide if they are visible to other modules. But luckily, Sema can handle it perfectly enough. So it is fine to make all of the in-class friend declaration as generally visible in ASTWriter and let the Sema to make the final call. This is safe as long as the corresponding class's visibility are correct.
Diffstat (limited to 'clang/lib/Serialization/ASTWriter.cpp')
-rw-r--r--clang/lib/Serialization/ASTWriter.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 3293a54..09859da 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -4297,10 +4297,18 @@ static bool isModuleLocalDecl(NamedDecl *D) {
if (auto *CDGD = dyn_cast<CXXDeductionGuideDecl>(FTD->getTemplatedDecl()))
return isModuleLocalDecl(CDGD->getDeducedTemplate());
- if (D->getFormalLinkage() == Linkage::Module)
- return true;
+ if (D->getFormalLinkage() != Linkage::Module)
+ return false;
- return false;
+ // It is hard for the serializer to judge if the in-class friend declaration
+ // is visible or not, so we just transfer the task to Sema. It should be a
+ // safe decision since Sema is able to handle the lookup rules for in-class
+ // friend declarations good enough already.
+ if (D->getFriendObjectKind() &&
+ isa<CXXRecordDecl>(D->getLexicalDeclContext()))
+ return false;
+
+ return true;
}
static bool isTULocalInNamedModules(NamedDecl *D) {