From e7bd6defd71d24e9b58f18462bb32c92a355c05b Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 10 Jun 2015 20:30:23 +0000 Subject: [modules] Track all default template arguments for a given parameter across modules, and allow use of a default template argument if any of the parameters providing it is visible. llvm-svn: 239485 --- clang/lib/Sema/SemaLookup.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'clang/lib/Sema/SemaLookup.cpp') diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index d0a55b57c61..147b81bc597 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -1228,6 +1228,8 @@ Module *Sema::getOwningModule(Decl *Entity) { } void Sema::makeMergedDefinitionVisible(NamedDecl *ND, SourceLocation Loc) { + // FIXME: If ND is a template declaration, make the template parameters + // visible too. They're not (necessarily) within its DeclContext. if (auto *M = PP.getModuleContainingLocation(Loc)) Context.mergeDefinitionIntoModule(ND, M); else @@ -1282,6 +1284,30 @@ bool Sema::hasVisibleMergedDefinition(NamedDecl *Def) { return false; } +template +static bool hasVisibleDefaultArgument(Sema &S, const ParmDecl *D) { + if (!D->hasDefaultArgument()) + return false; + + while (D) { + auto &DefaultArg = D->getDefaultArgStorage(); + if (!DefaultArg.isInherited() && S.isVisible(D)) + return true; + + // If there was a previous default argument, maybe its parameter is visible. + D = DefaultArg.getInheritedFrom(); + } + return false; +} + +bool Sema::hasVisibleDefaultArgument(const NamedDecl *D) { + if (auto *P = dyn_cast(D)) + return ::hasVisibleDefaultArgument(*this, P); + if (auto *P = dyn_cast(D)) + return ::hasVisibleDefaultArgument(*this, P); + return ::hasVisibleDefaultArgument(*this, cast(D)); +} + /// \brief Determine whether a declaration is visible to name lookup. /// /// This routine determines whether the declaration D is visible in the current -- cgit v1.2.3