[clang] da2b415 - [clang] Add tracking source deduction guide for the explicitly-written
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 2 14:08:28 PST 2025
Author: Haojian Wu
Date: 2025-02-02T23:06:25+01:00
New Revision: da2b415b19d178d6b250bb6468ed4a207860adf7
URL: https://github.com/llvm/llvm-project/commit/da2b415b19d178d6b250bb6468ed4a207860adf7
DIFF: https://github.com/llvm/llvm-project/commit/da2b415b19d178d6b250bb6468ed4a207860adf7.diff
LOG: [clang] Add tracking source deduction guide for the explicitly-written
deduction guide.
We miss this case in the original f94c481543bdd3b11a668ad78d46593cf974788f commit.
Added:
Modified:
clang/lib/Sema/SemaTemplateDeductionGuide.cpp
clang/unittests/AST/ASTImporterTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
index 63592c335d211be..0d079677eecc568 100644
--- a/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
+++ b/clang/lib/Sema/SemaTemplateDeductionGuide.cpp
@@ -1227,11 +1227,14 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
NewParam->setScopeInfo(0, I);
FPTL.setParam(I, NewParam);
}
- auto *Transformed = cast<FunctionDecl>(buildDeductionGuide(
+ auto *Transformed = cast<CXXDeductionGuideDecl>(buildDeductionGuide(
SemaRef, AliasTemplate, /*TemplateParams=*/nullptr,
/*Constructor=*/nullptr, DG->getExplicitSpecifier(), FunctionType,
AliasTemplate->getBeginLoc(), AliasTemplate->getLocation(),
AliasTemplate->getEndLoc(), DG->isImplicit()));
+ Transformed->setSourceDeductionGuide(DG);
+ Transformed->setSourceDeductionGuideKind(
+ CXXDeductionGuideDecl::SourceDeductionGuideKind::Alias);
// FIXME: Here the synthesized deduction guide is not a templated
// function. Per [dcl.decl]p4, the requires-clause shall be present only
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index 114d0b461dae880..0bac95eb40b2096 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -8193,6 +8193,29 @@ TEST_P(ImportFunctions, CTADAliasTemplate) {
EXPECT_TRUE(ToD->getSourceDeductionGuide());
}
+TEST_P(ImportFunctions, CTADAliasTemplateWithExplicitSourceDeductionGuide) {
+ Decl *TU = getTuDecl(
+ R"(
+ template <typename T> struct A {
+ A(T);
+ };
+ template<typename T>
+ using B = A<T>;
+ A(int) -> A<double>; // explicit
+ B b{(int)0};
+ )",
+ Lang_CXX20, "input.cc");
+ auto *FromD = FirstDeclMatcher<CXXDeductionGuideDecl>().match(
+ TU, cxxDeductionGuideDecl(hasParameter(0, hasType(asString("int"))),
+ hasName("<deduction guide for B>"),
+ hasReturnTypeLoc(loc(asString("A<double>")))));
+ auto *ToD = Import(FromD, Lang_CXX20);
+ ASSERT_TRUE(ToD);
+ EXPECT_TRUE(ToD->getSourceDeductionGuideKind() ==
+ CXXDeductionGuideDecl::SourceDeductionGuideKind::Alias);
+ EXPECT_TRUE(ToD->getSourceDeductionGuide());
+}
+
TEST_P(ImportFunctions, ParmVarDeclDeclContext) {
constexpr auto FromTUCode = R"(
void f(int P);
More information about the cfe-commits
mailing list