r239936 - [modules] If we merge a template, also track that its parameters are merged so

Richard Smith richard-llvm at metafoo.co.uk
Wed Jun 17 13:39:42 PDT 2015


Author: rsmith
Date: Wed Jun 17 15:39:41 2015
New Revision: 239936

URL: http://llvm.org/viewvc/llvm-project?rev=239936&view=rev
Log:
[modules] If we merge a template, also track that its parameters are merged so
that we know when its default arguments should be visible.

Modified:
    cfe/trunk/lib/Sema/SemaLookup.cpp
    cfe/trunk/test/Modules/submodules-merge-defs.cpp

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=239936&r1=239935&r2=239936&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Wed Jun 17 15:39:41 2015
@@ -1228,13 +1228,17 @@ Module *Sema::getOwningModule(Decl *Enti
 }
 
 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
     // We're not building a module; just make the definition visible.
     ND->setHidden(false);
+
+  // If ND is a template declaration, make the template parameters
+  // visible too. They're not (necessarily) within a mergeable DeclContext.
+  if (auto *TD = dyn_cast<TemplateDecl>(ND))
+    for (auto *Param : *TD->getTemplateParameters())
+      makeMergedDefinitionVisible(Param, Loc);
 }
 
 /// \brief Find the module in which the given declaration was defined.
@@ -1296,8 +1300,12 @@ hasVisibleDefaultArgument(Sema &S, const
     if (!DefaultArg.isInherited() && S.isVisible(D))
       return true;
 
-    if (!DefaultArg.isInherited() && Modules)
-      Modules->push_back(S.getOwningModule(const_cast<ParmDecl*>(D)));
+    if (!DefaultArg.isInherited() && Modules) {
+      auto *NonConstD = const_cast<ParmDecl*>(D);
+      Modules->push_back(S.getOwningModule(NonConstD));
+      const auto &Merged = S.Context.getModulesWithMergedDefinition(NonConstD);
+      Modules->insert(Modules->end(), Merged.begin(), Merged.end());
+    }
 
     // If there was a previous default argument, maybe its parameter is visible.
     D = DefaultArg.getInheritedFrom();

Modified: cfe/trunk/test/Modules/submodules-merge-defs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/submodules-merge-defs.cpp?rev=239936&r1=239935&r2=239936&view=diff
==============================================================================
--- cfe/trunk/test/Modules/submodules-merge-defs.cpp (original)
+++ cfe/trunk/test/Modules/submodules-merge-defs.cpp Wed Jun 17 15:39:41 2015
@@ -50,12 +50,11 @@ int pre_fg = F<int>().g<int>(); // expec
 
 J<> pre_j; // expected-error {{declaration of 'J' must be imported}}
 #ifdef IMPORT_USE_2
-// FIXME-error-re at -2 {{default argument of 'J' must be imported from one of {{.*}}stuff.use{{.*}}stuff.use-2}}
-// expected-error at -3 {{default argument of 'J' must be imported from module 'stuff.use'}}
+// expected-error-re at -2 {{default argument of 'J' must be imported from one of {{.*}}stuff.use{{.*}}stuff.use-2}}
 #elif EARLY_INDIRECT_INCLUDE
-// expected-error at -5 {{default argument of 'J' must be imported from module 'merged-defs'}}
+// expected-error at -4 {{default argument of 'J' must be imported from module 'merged-defs'}}
 #else
-// expected-error at -7 {{default argument of 'J' must be imported from module 'stuff.use'}}
+// expected-error at -6 {{default argument of 'J' must be imported from module 'stuff.use'}}
 #endif
 // expected-note at defs.h:49 +{{here}}
 





More information about the cfe-commits mailing list