[clang] [clang]: fix overload resolution in case of converting const value reference to an rvalue reference. (PR #133035)
Nhat Nguyen via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 25 23:26:34 PDT 2025
https://github.com/changkhothuychung updated https://github.com/llvm/llvm-project/pull/133035
>From fb9260dd796ae687a000beb550198d155b772625 Mon Sep 17 00:00:00 2001
From: changkhothuychung <nhat7203 at gmail.com>
Date: Wed, 26 Mar 2025 00:55:26 -0400
Subject: [PATCH 1/4] initial commit
---
clang/lib/Sema/SemaOverload.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 6d8006b35dcf4..28843f378c686 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -5419,7 +5419,7 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
// the argument expression. Any difference in top-level
// cv-qualification is subsumed by the initialization itself
// and does not constitute a conversion.
- ICS = TryImplicitConversion(S, Init, T1, SuppressUserConversions,
+ ICS = TryImplicitConversion(S, Init, DeclType, SuppressUserConversions,
AllowedExplicit::None,
/*InOverloadResolution=*/false,
/*CStyle=*/false,
>From 693049e2bdfe31c1243c9d9a5a7bf59363a2b9b1 Mon Sep 17 00:00:00 2001
From: changkhothuychung <nhat7203 at gmail.com>
Date: Wed, 26 Mar 2025 01:59:45 -0400
Subject: [PATCH 2/4] bound rref to const lref
---
clang/lib/Sema/SemaOverload.cpp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 28843f378c686..0f4bb69f713f8 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -5419,7 +5419,7 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
// the argument expression. Any difference in top-level
// cv-qualification is subsumed by the initialization itself
// and does not constitute a conversion.
- ICS = TryImplicitConversion(S, Init, DeclType, SuppressUserConversions,
+ ICS = TryImplicitConversion(S, Init, T1, SuppressUserConversions,
AllowedExplicit::None,
/*InOverloadResolution=*/false,
/*CStyle=*/false,
@@ -5450,6 +5450,11 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
return ICS;
}
+ if (isRValRef && ICS.UserDefined.ConversionFunction->getReturnType().isConstQualified()) {
+ ICS.setBad(BadConversionSequence::no_conversion, Init, DeclType);
+ return ICS;
+ }
+
ICS.UserDefined.After.ReferenceBinding = true;
ICS.UserDefined.After.IsLvalueReference = !isRValRef;
ICS.UserDefined.After.BindsToFunctionLvalue = false;
>From 01f5ee3e019a69f42aa22394e2aa9dd79b47c7ca Mon Sep 17 00:00:00 2001
From: changkhothuychung <nhat7203 at gmail.com>
Date: Wed, 26 Mar 2025 02:16:03 -0400
Subject: [PATCH 3/4] clang-format
---
clang/lib/Sema/SemaOverload.cpp | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 0f4bb69f713f8..5539934aef7f9 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -5450,10 +5450,11 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
return ICS;
}
- if (isRValRef && ICS.UserDefined.ConversionFunction->getReturnType().isConstQualified()) {
- ICS.setBad(BadConversionSequence::no_conversion, Init, DeclType);
- return ICS;
- }
+ if (isRValRef && ICS.UserDefined.ConversionFunction->getReturnType()
+ .isConstQualified()) {
+ ICS.setBad(BadConversionSequence::no_conversion, Init, DeclType);
+ return ICS;
+ }
ICS.UserDefined.After.ReferenceBinding = true;
ICS.UserDefined.After.IsLvalueReference = !isRValRef;
>From 36e6aa95a043bb4c9fe2275d331dc164fca43241 Mon Sep 17 00:00:00 2001
From: changkhothuychung <nhat7203 at gmail.com>
Date: Wed, 26 Mar 2025 02:26:22 -0400
Subject: [PATCH 4/4] clang format
---
clang/lib/Sema/SemaOverload.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 5539934aef7f9..c0e4a8ab51d05 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -5452,8 +5452,8 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
if (isRValRef && ICS.UserDefined.ConversionFunction->getReturnType()
.isConstQualified()) {
- ICS.setBad(BadConversionSequence::no_conversion, Init, DeclType);
- return ICS;
+ ICS.setBad(BadConversionSequence::no_conversion, Init, DeclType);
+ return ICS;
}
ICS.UserDefined.After.ReferenceBinding = true;
More information about the cfe-commits
mailing list