Skip to content

[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

Merged
merged 1 commit into from
Apr 4, 2025
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
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaTemplateDeduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())))
Comment on lines 4448 to 4451
Copy link
Contributor

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.

TDF |= TDF_DerivedClass;
Expand Down
16 changes: 16 additions & 0 deletions clang/test/Sema/nullability-and-template-deduction.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
Loading