Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Clang] Don't retain template FoundDecl for conversion function calls #138377

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
May 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
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ Bug Fixes to C++ Support
- Clang no longer crashes when establishing subsumption between some constraint expressions. (#GH122581)
- Clang now issues an error when placement new is used to modify a const-qualified variable
in a ``constexpr`` function. (#GH131432)
- Fixed an incorrect TreeTransform for calls to ``consteval`` functions if a conversion template is present. (#GH137885)
- Clang now emits a warning when class template argument deduction for alias templates is used in C++17. (#GH133806)

Bug Fixes to AST Handling
Expand Down
8 changes: 7 additions & 1 deletion clang/lib/Sema/SemaOverload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3977,7 +3977,7 @@ IsUserDefinedConversion(Sema &S, Expr *From, QualType ToType,
// phase of [over.match.list] when the initializer list has exactly
// one element that is itself an initializer list, [...] and the
// conversion is to X or reference to cv X, user-defined conversion
// sequences are not cnosidered.
// sequences are not considered.
if (SuppressUserConversions && ListInitializing) {
SuppressUserConversions =
NumArgs == 1 && isa<InitListExpr>(Args[0]) &&
Expand Down Expand Up @@ -14750,6 +14750,12 @@ ExprResult Sema::CreateUnresolvedLookupExpr(CXXRecordDecl *NamingClass,
ExprResult Sema::BuildCXXMemberCallExpr(Expr *E, NamedDecl *FoundDecl,
CXXConversionDecl *Method,
bool HadMultipleCandidates) {
// FoundDecl can be the TemplateDecl of Method. Don't retain a template in
// the FoundDecl as it impedes TransformMemberExpr.
// We go a bit further here: if there's no difference in UnderlyingDecl,
// then using FoundDecl vs Method shouldn't make a difference either.
if (FoundDecl->getUnderlyingDecl() == FoundDecl)
FoundDecl = Method;
// Convert the expression to match the conversion function's implicit object
// parameter.
ExprResult Exp;
Expand Down
28 changes: 28 additions & 0 deletions clang/test/SemaCXX/cxx2a-consteval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,3 +1272,31 @@ int main() {
}

} // namespace GH107175

namespace GH137885 {

template <typename... P> struct A {};

template <int N>
struct B {
consteval B() {}

template <typename... P> consteval operator A<P...>() const {
static_assert(sizeof...(P) == N);
return {};
}
};

template <typename T> struct type_identity {
using type = T;
};

template <typename... P>
void foo(typename type_identity<A<P...>>::type a, P...) {}

void foo() {
foo(B<0>());
foo(B<5>(), 1, 2, 3, 4, 5);
}

}