[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)

Max Winkler via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 31 21:31:16 PDT 2024


================
@@ -4446,6 +4446,24 @@ CompareStandardConversionSequences(Sema &S, SourceLocation Loc,
         T1 = S.Context.getQualifiedType(UnqualT1, T1Quals);
       if (isa<ArrayType>(T2) && T2Quals)
         T2 = S.Context.getQualifiedType(UnqualT2, T2Quals);
+
+      if (S.getLangOpts().MSVCReferenceBinding &&
+          S.Context.hasSameType(SCS1.getFromType(), SCS2.getFromType()) &&
+          !SCS1.getFromType().hasQualifiers() && SCS1.BindsToRvalue &&
+          SCS2.BindsToRvalue) {
+
+        // When binding a user-defined type temporary to an lvalue MSVC will
+        // pick `const T&` over `T&` when binding an unqualified `T&&`.
+        // Therefore we want to pick the more qualified const overload in this
+        // specific case.
----------------
MaxEW707 wrote:

https://godbolt.org/z/xaPE6rMc1 for reference on this overload resolution case.

https://github.com/llvm/llvm-project/pull/99833


More information about the cfe-commits mailing list