Skip to content

[clang] Fix CTAD not work for C++ explicit type conversion (functional annotation). #75779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,9 @@ Bug Fixes in This Version
- Fix an issue where clang doesn't respect detault template arguments that
are added in a later redeclaration for CTAD.
Fixes (#69987 <https://github.com/llvm/llvm-project/issues/69987>`_)
- Fix an issue where CTAD fails for explicit type conversion.
Fixes (#64347 <https://github.com/llvm/llvm-project/issues/64347>`_)


Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
3 changes: 1 addition & 2 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -9354,8 +9354,7 @@ class Sema final {

QualType DeduceTemplateSpecializationFromInitializer(
TypeSourceInfo *TInfo, const InitializedEntity &Entity,
const InitializationKind &Kind, MultiExprArg Init,
ParenListExpr *PL = nullptr);
const InitializationKind &Kind, MultiExprArg Init);

QualType deduceVarTypeFromInitializer(VarDecl *VDecl, DeclarationName Name,
QualType Type, TypeSourceInfo *TSI,
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12957,7 +12957,7 @@ QualType Sema::deduceVarTypeFromInitializer(VarDecl *VDecl,
// FIXME: Initialization should not be taking a mutable list of inits.
SmallVector<Expr*, 8> InitsCopy(DeduceInits.begin(), DeduceInits.end());
return DeduceTemplateSpecializationFromInitializer(TSI, Entity, Kind,
InitsCopy, PL);
InitsCopy);
}

if (DirectInit) {
Expand Down
11 changes: 7 additions & 4 deletions clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10561,7 +10561,7 @@ static bool isOrIsDerivedFromSpecializationOf(CXXRecordDecl *RD,

QualType Sema::DeduceTemplateSpecializationFromInitializer(
TypeSourceInfo *TSInfo, const InitializedEntity &Entity,
const InitializationKind &Kind, MultiExprArg Inits, ParenListExpr *PL) {
const InitializationKind &Kind, MultiExprArg Inits) {
auto *DeducedTST = dyn_cast<DeducedTemplateSpecializationType>(
TSInfo->getType()->getContainedDeducedType());
assert(DeducedTST && "not a deduced template specialization type");
Expand Down Expand Up @@ -10792,9 +10792,12 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer(
if (getLangOpts().CPlusPlus20 && !HasAnyDeductionGuide) {
if (ListInit && ListInit->getNumInits()) {
SynthesizeAggrGuide(ListInit);
} else if (PL && PL->getNumExprs()) {
InitListExpr TempListInit(getASTContext(), PL->getLParenLoc(),
PL->exprs(), PL->getRParenLoc());
} else if (Inits.size()) { // parenthesized expression-list
// Inits are expressions inside the parentheses. We don't have
// the parentheses source locations, use the begin/end of Inits as the
// best heuristic.
InitListExpr TempListInit(getASTContext(), Inits.front()->getBeginLoc(),
Inits, Inits.back()->getEndLoc());
SynthesizeAggrGuide(&TempListInit);
}
}
Expand Down
19 changes: 19 additions & 0 deletions clang/test/SemaCXX/ctad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value -std=c++20 %s
// expected-no-diagnostics

namespace GH64347 {

template<typename X, typename Y> struct A { X x; Y y;};
void test() {
A(1, 2);
new A(1, 2);
}

template<A a>
void f() { (void)a; }
void k() {
// Test CTAD works for non-type template arguments.
f<A(0, 0)>();
}

} // namespace GH64347