r321297 - When instantiating a deduction guide, transform its name.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 21 11:43:39 PST 2017
Author: rsmith
Date: Thu Dec 21 11:43:39 2017
New Revision: 321297
URL: http://llvm.org/viewvc/llvm-project?rev=321297&view=rev
Log:
When instantiating a deduction guide, transform its name.
Otherwise it will serve as a deduction guide for the wrong class template.
Added:
cfe/trunk/test/SemaTemplate/nested-deduction-guides.cpp
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=321297&r1=321296&r2=321297&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu Dec 21 11:43:39 2017
@@ -1587,9 +1587,10 @@ static QualType adjustFunctionTypeForIns
}
/// Normal class members are of more specific types and therefore
-/// don't make it here. This function serves two purposes:
+/// don't make it here. This function serves three purposes:
/// 1) instantiating function templates
/// 2) substituting friend declarations
+/// 3) substituting deduction guide declarations for nested class templates
Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D,
TemplateParameterList *TemplateParams) {
// Check whether there is already a function template specialization for
@@ -1650,16 +1651,19 @@ Decl *TemplateDeclInstantiator::VisitFun
TemplateArgs);
}
+ DeclarationNameInfo NameInfo
+ = SemaRef.SubstDeclarationNameInfo(D->getNameInfo(), TemplateArgs);
+
FunctionDecl *Function;
if (auto *DGuide = dyn_cast<CXXDeductionGuideDecl>(D)) {
Function = CXXDeductionGuideDecl::Create(
SemaRef.Context, DC, D->getInnerLocStart(), DGuide->isExplicit(),
- D->getNameInfo(), T, TInfo, D->getSourceRange().getEnd());
+ NameInfo, T, TInfo, D->getSourceRange().getEnd());
if (DGuide->isCopyDeductionCandidate())
cast<CXXDeductionGuideDecl>(Function)->setIsCopyDeductionCandidate();
} else {
Function = FunctionDecl::Create(
- SemaRef.Context, DC, D->getInnerLocStart(), D->getNameInfo(), T, TInfo,
+ SemaRef.Context, DC, D->getInnerLocStart(), NameInfo, T, TInfo,
D->getCanonicalDecl()->getStorageClass(), D->isInlineSpecified(),
D->hasWrittenPrototype(), D->isConstexpr());
Function->setRangeEnd(D->getSourceRange().getEnd());
Added: cfe/trunk/test/SemaTemplate/nested-deduction-guides.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/nested-deduction-guides.cpp?rev=321297&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/nested-deduction-guides.cpp (added)
+++ cfe/trunk/test/SemaTemplate/nested-deduction-guides.cpp Thu Dec 21 11:43:39 2017
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// expected-no-diagnostics
+
+template<typename T> struct A {
+ template<typename U> struct B {
+ B(...);
+ };
+ template<typename U> B(U) -> B<U>;
+};
+A<void>::B b = 123;
+
+using T = decltype(b);
+using T = A<void>::B<int>;
More information about the cfe-commits
mailing list