https://github.com/hokein created https://github.com/llvm/llvm-project/pull/78159
Fixes https://github.com/llvm/llvm-project/issues/51710 >From f86766ff519ab2b802c0f1ac6c8138cbeadd543a Mon Sep 17 00:00:00 2001 From: Haojian Wu <hokein...@gmail.com> Date: Mon, 15 Jan 2024 14:30:18 +0100 Subject: [PATCH] [clang] Fix CTAD not work for function-type and array-type arguments. Fixes https://github.com/llvm/llvm-project/issues/51710 --- clang/docs/ReleaseNotes.rst | 2 ++ clang/lib/Sema/SemaTemplate.cpp | 8 +++++++- clang/test/SemaCXX/ctad-decay.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/ctad-decay.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 4aba054e252af24..82302bae6d6dc28 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -726,6 +726,8 @@ Bug Fixes in This Version - Fix an issue where clang cannot find conversion function with template parameter when instantiation of template class. Fixes (`#77583 <https://github.com/llvm/llvm-project/issues/77583>`_) +- Fix an issue where CTAD fails for function-type/array-type arguments. + Fixes (`#51710 <https://github.com/llvm/llvm-project/issues/51710>`_) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 5fcc39ec7005228..3052b01f7f12ac3 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -2587,12 +2587,18 @@ struct ConvertConstructorToDeductionGuideTransform { : ParamTy->isRValueReferenceType() ? VK_XValue : VK_PRValue); } + // Handle arrays and functions decay. + auto NewType = NewDI->getType(); + if (NewType->isArrayType()) + NewType = SemaRef.Context.getArrayDecayedType(NewType); + else if (NewType->isFunctionType()) + NewType = SemaRef.Context.getPointerType(NewType); ParmVarDecl *NewParam = ParmVarDecl::Create(SemaRef.Context, DC, OldParam->getInnerLocStart(), OldParam->getLocation(), OldParam->getIdentifier(), - NewDI->getType(), + NewType, NewDI, OldParam->getStorageClass(), NewDefArg.get()); diff --git a/clang/test/SemaCXX/ctad-decay.cpp b/clang/test/SemaCXX/ctad-decay.cpp new file mode 100644 index 000000000000000..97063e8fb75659f --- /dev/null +++ b/clang/test/SemaCXX/ctad-decay.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value -std=c++20 %s +// expected-no-diagnostics + +namespace GH51710 { + +template<typename T> +struct A{ + A(T f()); + A(int f(), T); + + A(T array[10]); + A(int array[10], T); +}; + +int foo(); + +void bar() { + A test1(foo); + A test2(foo, 1); + + int array[10]; + A test3(array); + A test4(array, 1); +} + +} // namespace GH51710 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits