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

This commit is contained in:
Younan Zhang
2025-05-04 19:27:08 +08:00
committed by GitHub
parent 4e81ee4a15
commit 1b60b83ada
3 changed files with 36 additions and 1 deletions

View File

@@ -637,6 +637,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)
- Fix a crash when checking the template template parameters of a dependent lambda appearing in an alias declaration.
(#GH136432), (#GH137014), (#GH138018)

View File

@@ -3983,7 +3983,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]) &&
@@ -14765,6 +14765,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;

View File

@@ -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);
}
}