diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -463,7 +463,7 @@ ParmVarDecl *ToParam); template - bool hasSameVisibilityContext(T *Found, T *From); + bool hasSameVisibilityContextAndLinkage(T *Found, T *From); bool IsStructuralMatch(Decl *From, Decl *To, bool Complain); bool IsStructuralMatch(RecordDecl *FromRecord, RecordDecl *ToRecord, @@ -973,7 +973,10 @@ } template -bool ASTNodeImporter::hasSameVisibilityContext(T *Found, T *From) { +bool ASTNodeImporter::hasSameVisibilityContextAndLinkage(T *Found, T *From) { + if (Found->getLinkageInternal() != From->getLinkageInternal()) + return false; + if (From->hasExternalFormalLinkage()) return Found->hasExternalFormalLinkage(); if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl()) @@ -986,8 +989,11 @@ } template <> -bool ASTNodeImporter::hasSameVisibilityContext(TypedefNameDecl *Found, +bool ASTNodeImporter::hasSameVisibilityContextAndLinkage(TypedefNameDecl *Found, TypedefNameDecl *From) { + if (Found->getLinkageInternal() != From->getLinkageInternal()) + return false; + if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace()) return Importer.GetFromTU(Found) == From->getTranslationUnitDecl(); return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace(); @@ -2392,7 +2398,7 @@ if (!FoundDecl->isInIdentifierNamespace(IDNS)) continue; if (auto *FoundTypedef = dyn_cast(FoundDecl)) { - if (!hasSameVisibilityContext(FoundTypedef, D)) + if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D)) continue; QualType FromUT = D->getUnderlyingType(); @@ -2593,7 +2599,7 @@ } if (auto *FoundEnum = dyn_cast(FoundDecl)) { - if (!hasSameVisibilityContext(FoundEnum, D)) + if (!hasSameVisibilityContextAndLinkage(FoundEnum, D)) continue; if (IsStructuralMatch(D, FoundEnum)) { EnumDecl *FoundDef = FoundEnum->getDefinition(); @@ -2715,7 +2721,7 @@ if (!IsStructuralMatch(D, FoundRecord, false)) continue; - if (!hasSameVisibilityContext(FoundRecord, D)) + if (!hasSameVisibilityContextAndLinkage(FoundRecord, D)) continue; if (IsStructuralMatch(D, FoundRecord)) { @@ -3163,7 +3169,7 @@ continue; if (auto *FoundFunction = dyn_cast(FoundDecl)) { - if (!hasSameVisibilityContext(FoundFunction, D)) + if (!hasSameVisibilityContextAndLinkage(FoundFunction, D)) continue; if (IsStructuralMatch(D, FoundFunction)) { @@ -3785,7 +3791,7 @@ continue; if (auto *FoundVar = dyn_cast(FoundDecl)) { - if (!hasSameVisibilityContext(FoundVar, D)) + if (!hasSameVisibilityContextAndLinkage(FoundVar, D)) continue; if (Importer.IsStructurallyEquivalent(D->getType(), FoundVar->getType())) { @@ -5191,7 +5197,7 @@ Decl *Found = FoundDecl; auto *FoundTemplate = dyn_cast(Found); if (FoundTemplate) { - if (!hasSameVisibilityContext(FoundTemplate, D)) + if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D)) continue; if (IsStructuralMatch(D, FoundTemplate)) { @@ -5719,7 +5725,7 @@ continue; if (auto *FoundTemplate = dyn_cast(FoundDecl)) { - if (!hasSameVisibilityContext(FoundTemplate, D)) + if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D)) continue; if (IsStructuralMatch(D, FoundTemplate)) { FunctionTemplateDecl *TemplateWithDef =