-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[Sema] Handle AttributedType in template deduction with derived-to-base conversions #134361
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
Conversation
…se conversions Fix llvm#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.
@llvm/pr-subscribers-clang Author: Ilya Biryukov (ilya-biryukov) ChangesFix #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:
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);
+}
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/134/builds/16302 Here is the relevant piece of the build log for the reference
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have had a release note.
if (isSimpleTemplateIdType(ParamType) || | ||
(isa<PointerType>(ParamType) && | ||
(ParamType->getAs<PointerType>() && | ||
isSimpleTemplateIdType( | ||
ParamType->castAs<PointerType>()->getPointeeType()))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could avoid searching for the PointerType twice.
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.