<div dir="ltr">Reverted this per Richard's request in r279500.<br><br><div class="gmail_quote"><div dir="ltr">On Mon, Aug 22, 2016 at 3:33 PM Richard Smith via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rsmith<br>
Date: Mon Aug 22 17:25:03 2016<br>
New Revision: 279486<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=279486&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=279486&view=rev</a><br>
Log:<br>
Fix regression introduced by r279164: only pass definitions as the PatternDef<br>
to DiagnoseUninstantiableTemplate, teach hasVisibleDefinition to correctly<br>
determine whether a function definition is visible, and mark both the function<br>
and the template as visible when merging function template definitions to<br>
provide hasVisibleDefinition with the relevant information.<br>
<br>
The change to always pass the right declaration as the PatternDef to<br>
DiagnoseUninstantiableTemplate also caused those checks to happen before other<br>
diagnostics in InstantiateFunctionDefinition, giving worse diagnostics for the<br>
same situations, so I sunk the relevant diagnostics into<br>
DiagnoseUninstantiableTemplate. Those parts of this patch are based on changes<br>
in <a href="http://reviews.llvm.org/D23492" rel="noreferrer" target="_blank">reviews.llvm.org/D23492</a> by Vassil Vassilev.<br>
<br>
Modified:<br>
cfe/trunk/lib/Sema/SemaDecl.cpp<br>
cfe/trunk/lib/Sema/SemaTemplate.cpp<br>
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp<br>
cfe/trunk/lib/Sema/SemaType.cpp<br>
cfe/trunk/test/Modules/Inputs/merge-template-pattern-visibility/a.h<br>
cfe/trunk/test/Modules/Inputs/merge-template-pattern-visibility/b.h<br>
cfe/trunk/test/Modules/merge-template-pattern-visibility.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=279486&r1=279485&r2=279486&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=279486&r1=279485&r2=279486&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Aug 22 17:25:03 2016<br>
@@ -11274,9 +11274,8 @@ Sema::CheckForFunctionRedefinition(Funct<br>
SkipBody->ShouldSkip = true;<br>
if (auto *TD = Definition->getDescribedFunctionTemplate())<br>
makeMergedDefinitionVisible(TD, FD->getLocation());<br>
- else<br>
- makeMergedDefinitionVisible(const_cast<FunctionDecl*>(Definition),<br>
- FD->getLocation());<br>
+ makeMergedDefinitionVisible(const_cast<FunctionDecl*>(Definition),<br>
+ FD->getLocation());<br>
return;<br>
}<br>
<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=279486&r1=279485&r2=279486&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=279486&r1=279485&r2=279486&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon Aug 22 17:25:03 2016<br>
@@ -487,8 +487,6 @@ bool Sema::DiagnoseUninstantiableTemplat<br>
QualType InstantiationTy;<br>
if (TagDecl *TD = dyn_cast<TagDecl>(Instantiation))<br>
InstantiationTy = Context.getTypeDeclType(TD);<br>
- else<br>
- InstantiationTy = cast<FunctionDecl>(Instantiation)->getType();<br>
if (!Complain || (PatternDef && PatternDef->isInvalidDecl())) {<br>
// Say nothing<br>
} else if (PatternDef) {<br>
@@ -500,15 +498,30 @@ bool Sema::DiagnoseUninstantiableTemplat<br>
// we're lexically inside it.<br>
Instantiation->setInvalidDecl();<br>
} else if (InstantiatedFromMember) {<br>
- Diag(PointOfInstantiation,<br>
- diag::err_implicit_instantiate_member_undefined)<br>
- << InstantiationTy;<br>
- Diag(Pattern->getLocation(), diag::note_member_declared_at);<br>
+ if (isa<FunctionDecl>(Instantiation)) {<br>
+ Diag(PointOfInstantiation,<br>
+ diag::err_explicit_instantiation_undefined_member)<br>
+ << 1 << Instantiation->getDeclName() << Instantiation->getDeclContext();<br>
+ } else {<br>
+ Diag(PointOfInstantiation,<br>
+ diag::err_implicit_instantiate_member_undefined)<br>
+ << InstantiationTy;<br>
+ }<br>
+ Diag(Pattern->getLocation(), isa<FunctionDecl>(Instantiation)<br>
+ ? diag::note_explicit_instantiation_here<br>
+ : diag::note_member_declared_at);<br>
} else {<br>
- Diag(PointOfInstantiation, diag::err_template_instantiate_undefined)<br>
- << (TSK != TSK_ImplicitInstantiation)<br>
- << InstantiationTy;<br>
- Diag(Pattern->getLocation(), diag::note_template_decl_here);<br>
+ if (isa<FunctionDecl>(Instantiation))<br>
+ Diag(PointOfInstantiation,<br>
+ diag::err_explicit_instantiation_undefined_func_template)<br>
+ << Pattern;<br>
+ else<br>
+ Diag(PointOfInstantiation, diag::err_template_instantiate_undefined)<br>
+ << (TSK != TSK_ImplicitInstantiation)<br>
+ << InstantiationTy;<br>
+ Diag(Pattern->getLocation(), isa<FunctionDecl>(Instantiation)<br>
+ ? diag::note_explicit_instantiation_here<br>
+ : diag::note_template_decl_here);<br>
}<br>
<br>
// In general, Instantiation isn't marked invalid to get more than one<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=279486&r1=279485&r2=279486&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=279486&r1=279485&r2=279486&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon Aug 22 17:25:03 2016<br>
@@ -3554,23 +3554,38 @@ void Sema::InstantiateFunctionDefinition<br>
const FunctionDecl *PatternDecl = Function->getTemplateInstantiationPattern();<br>
assert(PatternDecl && "instantiating a non-template");<br>
<br>
- Stmt *Pattern = PatternDecl->getBody(PatternDecl);<br>
- assert(PatternDecl && "template definition is not a template");<br>
- if (!Pattern) {<br>
- // Try to find a defaulted definition<br>
- PatternDecl->isDefined(PatternDecl);<br>
- }<br>
- assert(PatternDecl && "template definition is not a template");<br>
+ const FunctionDecl *PatternDef = PatternDecl->getDefinition();<br>
+ Stmt *Pattern = PatternDef->getBody(PatternDef);<br>
+ if (PatternDef)<br>
+ PatternDecl = PatternDef;<br>
<br>
// FIXME: We need to track the instantiation stack in order to know which<br>
// definitions should be visible within this instantiation.<br>
if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Function,<br>
Function->getInstantiatedFromMemberFunction(),<br>
- PatternDecl, PatternDecl, TSK,<br>
- /*Complain*/DefinitionRequired))<br>
- return;<br>
-<br>
+ PatternDecl, PatternDef, TSK,<br>
+ /*Complain*/DefinitionRequired)) {<br>
+ if (DefinitionRequired)<br>
+ Function->setInvalidDecl();<br>
+ else if (TSK == TSK_ExplicitInstantiationDefinition) {<br>
+ // Try again at the end of the translation unit (at which point a<br>
+ // definition will be required).<br>
+ assert(!Recursive);<br>
+ PendingInstantiations.push_back(<br>
+ std::make_pair(Function, PointOfInstantiation));<br>
+ } else if (TSK == TSK_ImplicitInstantiation) {<br>
+ if (AtEndOfTU && !getDiagnostics().hasErrorOccurred()) {<br>
+ Diag(PointOfInstantiation, diag::warn_func_template_missing)<br>
+ << Function;<br>
+ Diag(PatternDecl->getLocation(), diag::note_forward_template_decl);<br>
+ if (getLangOpts().CPlusPlus11)<br>
+ Diag(PointOfInstantiation, diag::note_inst_declaration_hint)<br>
+ << Function;<br>
+ }<br>
+ }<br>
<br>
+ return;<br>
+ }<br>
<br>
// Postpone late parsed template instantiations.<br>
if (PatternDecl->isLateTemplateParsed() &&<br>
@@ -3604,40 +3619,9 @@ void Sema::InstantiateFunctionDefinition<br>
Pattern = PatternDecl->getBody(PatternDecl);<br>
}<br>
<br>
- // FIXME: Check if we could sink these diagnostics in<br>
- // DiagnoseUninstantiableTemplate.<br>
- if (!Pattern && !PatternDecl->isDefaulted()) {<br>
- if (DefinitionRequired) {<br>
- if (Function->getPrimaryTemplate())<br>
- Diag(PointOfInstantiation,<br>
- diag::err_explicit_instantiation_undefined_func_template)<br>
- << Function->getPrimaryTemplate();<br>
- else<br>
- Diag(PointOfInstantiation,<br>
- diag::err_explicit_instantiation_undefined_member)<br>
- << 1 << Function->getDeclName() << Function->getDeclContext();<br>
-<br>
- if (PatternDecl)<br>
- Diag(PatternDecl->getLocation(),<br>
- diag::note_explicit_instantiation_here);<br>
- Function->setInvalidDecl();<br>
- } else if (TSK == TSK_ExplicitInstantiationDefinition) {<br>
- assert(!Recursive);<br>
- PendingInstantiations.push_back(<br>
- std::make_pair(Function, PointOfInstantiation));<br>
- } else if (TSK == TSK_ImplicitInstantiation) {<br>
- if (AtEndOfTU && !getDiagnostics().hasErrorOccurred()) {<br>
- Diag(PointOfInstantiation, diag::warn_func_template_missing)<br>
- << Function;<br>
- Diag(PatternDecl->getLocation(), diag::note_forward_template_decl);<br>
- if (getLangOpts().CPlusPlus11)<br>
- Diag(PointOfInstantiation, diag::note_inst_declaration_hint)<br>
- << Function;<br>
- }<br>
- }<br>
-<br>
- return;<br>
- }<br>
+ // Note, we should never try to instantiate a deleted function template.<br>
+ assert((Pattern || PatternDecl->isDefaulted()) &&<br>
+ "unexpected kind of function template definition");<br>
<br>
// C++1y [temp.explicit]p10:<br>
// Except for inline functions, declarations with types deduced from their<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaType.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=279486&r1=279485&r2=279486&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=279486&r1=279485&r2=279486&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaType.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Aug 22 17:25:03 2016<br>
@@ -6890,6 +6890,10 @@ bool Sema::hasVisibleDefinition(NamedDec<br>
return false;<br>
}<br>
D = ED->getDefinition();<br>
+ } else if (auto *FD = dyn_cast<FunctionDecl>(D)) {<br>
+ if (auto *Pattern = FD->getTemplateInstantiationPattern())<br>
+ FD = Pattern;<br>
+ D = FD->getDefinition();<br>
}<br>
assert(D && "missing definition for pattern of instantiated definition");<br>
<br>
@@ -6897,7 +6901,7 @@ bool Sema::hasVisibleDefinition(NamedDec<br>
if (isVisible(D))<br>
return true;<br>
<br>
- // The external source may have additional definitions of this type that are<br>
+ // The external source may have additional definitions of this entity that are<br>
// visible, so complete the redeclaration chain now and ask again.<br>
if (auto *Source = Context.getExternalSource()) {<br>
Source->CompleteRedeclChain(D);<br>
<br>
Modified: cfe/trunk/test/Modules/Inputs/merge-template-pattern-visibility/a.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-template-pattern-visibility/a.h?rev=279486&r1=279485&r2=279486&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-template-pattern-visibility/a.h?rev=279486&r1=279485&r2=279486&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Modules/Inputs/merge-template-pattern-visibility/a.h (original)<br>
+++ cfe/trunk/test/Modules/Inputs/merge-template-pattern-visibility/a.h Mon Aug 22 17:25:03 2016<br>
@@ -3,3 +3,4 @@ template<typename T> struct B;<br>
<br>
template<typename, typename> struct A {};<br>
template<typename T> struct B : A<T> {};<br>
+template<typename T> inline auto C(T) {}<br>
<br>
Modified: cfe/trunk/test/Modules/Inputs/merge-template-pattern-visibility/b.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-template-pattern-visibility/b.h?rev=279486&r1=279485&r2=279486&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/merge-template-pattern-visibility/b.h?rev=279486&r1=279485&r2=279486&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Modules/Inputs/merge-template-pattern-visibility/b.h (original)<br>
+++ cfe/trunk/test/Modules/Inputs/merge-template-pattern-visibility/b.h Mon Aug 22 17:25:03 2016<br>
@@ -3,7 +3,9 @@ template<typename T> struct B;<br>
<br>
template<typename, typename> struct A {};<br>
template<typename T> struct B : A<T> {};<br>
+template<typename T> inline auto C(T) {}<br>
<br>
inline void f() {<br>
B<int> bi;<br>
+ C(0);<br>
}<br>
<br>
Modified: cfe/trunk/test/Modules/merge-template-pattern-visibility.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/merge-template-pattern-visibility.cpp?rev=279486&r1=279485&r2=279486&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/merge-template-pattern-visibility.cpp?rev=279486&r1=279485&r2=279486&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Modules/merge-template-pattern-visibility.cpp (original)<br>
+++ cfe/trunk/test/Modules/merge-template-pattern-visibility.cpp Mon Aug 22 17:25:03 2016<br>
@@ -1,4 +1,4 @@<br>
// RUN: rm -rf %t<br>
-// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fno-modules-error-recovery \<br>
+// RUN: %clang_cc1 -fmodules -fno-modules-error-recovery -std=c++14 \<br>
// RUN: -fmodule-name=X -emit-module %S/Inputs/merge-template-pattern-visibility/module.modulemap -x c++ \<br>
-// RUN: -fmodules-local-submodule-visibility<br>
+// RUN: -fmodules-local-submodule-visibility -o %t/X.pcm<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div>