https://github.com/ilya-biryukov created https://github.com/llvm/llvm-project/pull/134361
Fix #134356. We accidentally skipped checking derived-to-base conversions because deduction did not strip sugar in the relevant code. This caused deduction failures when a parameter type had an attribute. >From 061aa962704625e96c347014cf3ddbaa096406cc Mon Sep 17 00:00:00 2001 From: Ilya Biryukov <ibiryu...@google.com> Date: Fri, 4 Apr 2025 12:08:53 +0200 Subject: [PATCH] [Sema] Handle AttributedType in template deduction with derived-to-base conversions Fix #134356. We accidentally skipped checking derived-to-base conversions because deduction did not strip sugar in the relevant code. This caused deduction failures when a parameter type had an attribute. --- clang/lib/Sema/SemaTemplateDeduction.cpp | 2 +- .../Sema/nullability-and-template-deduction.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 clang/test/Sema/nullability-and-template-deduction.cpp diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 9969f1762fe36..92283867c38cd 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -4446,7 +4446,7 @@ static bool AdjustFunctionParmAndArgTypesForDeduction( // transformed A can be a pointer to a derived class pointed to by // the deduced A. if (isSimpleTemplateIdType(ParamType) || - (isa<PointerType>(ParamType) && + (ParamType->getAs<PointerType>() && isSimpleTemplateIdType( ParamType->castAs<PointerType>()->getPointeeType()))) TDF |= TDF_DerivedClass; diff --git a/clang/test/Sema/nullability-and-template-deduction.cpp b/clang/test/Sema/nullability-and-template-deduction.cpp new file mode 100644 index 0000000000000..3ea6d38d26b69 --- /dev/null +++ b/clang/test/Sema/nullability-and-template-deduction.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only %s -verify +// expected-no-diagnostics + +template <class T> struct Base {}; +template <class T> struct Derived : Base<T> {}; + +template <class T> void foo(Base<T> *_Nonnull); + +template <class T> void bar(Base<T> *); + + +void test() { + Derived<int> d; + foo(&d); + bar(&d); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits