Skip to content

Commit 163a43a

Browse files
committed
[clang] Fix CTAD not work for C++ explicit type conversion (functional
annotation). Fixes #64347
1 parent 73cf485 commit 163a43a

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,9 @@ Bug Fixes in This Version
686686
- Fix an issue where clang doesn't respect detault template arguments that
687687
are added in a later redeclaration for CTAD.
688688
Fixes (#69987 <https://github.com/llvm/llvm-project/issues/69987>`_)
689+
- Fix an issue where CTAD fails for explicit type conversion.
690+
Fixes (#64347 <https://github.com/llvm/llvm-project/issues/64347>`_)
691+
689692

690693
Bug Fixes to Compiler Builtins
691694
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12957,7 +12957,7 @@ QualType Sema::deduceVarTypeFromInitializer(VarDecl *VDecl,
1295712957
// FIXME: Initialization should not be taking a mutable list of inits.
1295812958
SmallVector<Expr*, 8> InitsCopy(DeduceInits.begin(), DeduceInits.end());
1295912959
return DeduceTemplateSpecializationFromInitializer(TSI, Entity, Kind,
12960-
InitsCopy, PL);
12960+
InitsCopy);
1296112961
}
1296212962

1296312963
if (DirectInit) {

clang/lib/Sema/SemaInit.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10561,7 +10561,7 @@ static bool isOrIsDerivedFromSpecializationOf(CXXRecordDecl *RD,
1056110561

1056210562
QualType Sema::DeduceTemplateSpecializationFromInitializer(
1056310563
TypeSourceInfo *TSInfo, const InitializedEntity &Entity,
10564-
const InitializationKind &Kind, MultiExprArg Inits, ParenListExpr *PL) {
10564+
const InitializationKind &Kind, MultiExprArg Inits) {
1056510565
auto *DeducedTST = dyn_cast<DeducedTemplateSpecializationType>(
1056610566
TSInfo->getType()->getContainedDeducedType());
1056710567
assert(DeducedTST && "not a deduced template specialization type");
@@ -10792,9 +10792,12 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer(
1079210792
if (getLangOpts().CPlusPlus20 && !HasAnyDeductionGuide) {
1079310793
if (ListInit && ListInit->getNumInits()) {
1079410794
SynthesizeAggrGuide(ListInit);
10795-
} else if (PL && PL->getNumExprs()) {
10796-
InitListExpr TempListInit(getASTContext(), PL->getLParenLoc(),
10797-
PL->exprs(), PL->getRParenLoc());
10795+
} else if (Inits.size()) { // parenthesized expression-list
10796+
// Inits are expressions inside the parentheses. We don't have
10797+
// the parentheses source locaitons, use the begin/end of Inits as the
10798+
// best heuristic.
10799+
InitListExpr TempListInit(getASTContext(), Inits.front()->getBeginLoc(),
10800+
Inits, Inits.back()->getEndLoc());
1079810801
SynthesizeAggrGuide(&TempListInit);
1079910802
}
1080010803
}

clang/test/SemaCXX/ctad.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value -std=c++20 %s
2+
// expected-no-diagnostics
3+
4+
namespace GH64347 {
5+
6+
template<typename X, typename Y> struct A { X x; Y y;};
7+
void test() {
8+
A(1, 2);
9+
new A(1, 2);
10+
}
11+
12+
template<A a>
13+
void f() { (void)a; }
14+
void k() {
15+
// Test CTAD works for non-type template arguments.
16+
f<A(0, 0)>();
17+
}
18+
19+
} // namespace GH64347

0 commit comments

Comments
 (0)