Skip to content

Commit 1b60b83

Browse files
authored
[Clang] Don't retain template FoundDecl for conversion function calls (#138377)
1 parent 4e81ee4 commit 1b60b83

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

clang/docs/ReleaseNotes.rst

+1
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ Bug Fixes to C++ Support
637637
- Clang no longer crashes when establishing subsumption between some constraint expressions. (#GH122581)
638638
- Clang now issues an error when placement new is used to modify a const-qualified variable
639639
in a ``constexpr`` function. (#GH131432)
640+
- Fixed an incorrect TreeTransform for calls to ``consteval`` functions if a conversion template is present. (#GH137885)
640641
- Clang now emits a warning when class template argument deduction for alias templates is used in C++17. (#GH133806)
641642
- Fix a crash when checking the template template parameters of a dependent lambda appearing in an alias declaration.
642643
(#GH136432), (#GH137014), (#GH138018)

clang/lib/Sema/SemaOverload.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -3983,7 +3983,7 @@ IsUserDefinedConversion(Sema &S, Expr *From, QualType ToType,
39833983
// phase of [over.match.list] when the initializer list has exactly
39843984
// one element that is itself an initializer list, [...] and the
39853985
// conversion is to X or reference to cv X, user-defined conversion
3986-
// sequences are not cnosidered.
3986+
// sequences are not considered.
39873987
if (SuppressUserConversions && ListInitializing) {
39883988
SuppressUserConversions =
39893989
NumArgs == 1 && isa<InitListExpr>(Args[0]) &&
@@ -14765,6 +14765,12 @@ ExprResult Sema::CreateUnresolvedLookupExpr(CXXRecordDecl *NamingClass,
1476514765
ExprResult Sema::BuildCXXMemberCallExpr(Expr *E, NamedDecl *FoundDecl,
1476614766
CXXConversionDecl *Method,
1476714767
bool HadMultipleCandidates) {
14768+
// FoundDecl can be the TemplateDecl of Method. Don't retain a template in
14769+
// the FoundDecl as it impedes TransformMemberExpr.
14770+
// We go a bit further here: if there's no difference in UnderlyingDecl,
14771+
// then using FoundDecl vs Method shouldn't make a difference either.
14772+
if (FoundDecl->getUnderlyingDecl() == FoundDecl)
14773+
FoundDecl = Method;
1476814774
// Convert the expression to match the conversion function's implicit object
1476914775
// parameter.
1477014776
ExprResult Exp;

clang/test/SemaCXX/cxx2a-consteval.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -1272,3 +1272,31 @@ int main() {
12721272
}
12731273

12741274
} // namespace GH107175
1275+
1276+
namespace GH137885 {
1277+
1278+
template <typename... P> struct A {};
1279+
1280+
template <int N>
1281+
struct B {
1282+
consteval B() {}
1283+
1284+
template <typename... P> consteval operator A<P...>() const {
1285+
static_assert(sizeof...(P) == N);
1286+
return {};
1287+
}
1288+
};
1289+
1290+
template <typename T> struct type_identity {
1291+
using type = T;
1292+
};
1293+
1294+
template <typename... P>
1295+
void foo(typename type_identity<A<P...>>::type a, P...) {}
1296+
1297+
void foo() {
1298+
foo(B<0>());
1299+
foo(B<5>(), 1, 2, 3, 4, 5);
1300+
}
1301+
1302+
}

0 commit comments

Comments
 (0)