[clang] [Sema] Handle AttributedType in template deduction with derived-to-base conversions (PR #134361)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 4 03:15:03 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Ilya Biryukov (ilya-biryukov)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/134361.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+1-1)
- (added) clang/test/Sema/nullability-and-template-deduction.cpp (+16)
``````````diff
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);
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/134361
More information about the cfe-commits
mailing list