[PATCH] D90123: [Sema] Improve notes for value category mismatch in overloading

Aaron Puchert via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 25 10:26:39 PDT 2020


aaronpuchert added inline comments.


================
Comment at: clang/lib/Sema/SemaOverload.cpp:4927
     // Note that the function case is not possible here.
-    if (DeclType->isRValueReferenceType() && LValRefType) {
-      // FIXME: This is the wrong BadConversionSequence. The problem is binding
-      // an rvalue reference to a (non-function) lvalue, not binding an lvalue
-      // reference to an rvalue!
-      ICS.setBad(BadConversionSequence::lvalue_ref_to_rvalue, Init, DeclType);
+    if (isRValRef && LValRefType) {
+      ICS.setBad(BadConversionSequence::no_conversion, Init, DeclType);
----------------
No functional change here, I was just using the existing prefetched value.


================
Comment at: clang/lib/Sema/SemaOverload.cpp:4928
+    if (isRValRef && LValRefType) {
+      ICS.setBad(BadConversionSequence::no_conversion, Init, DeclType);
       return ICS;
----------------
One might think that this should be `rvalue_ref_to_lvalue`, but we have a user-defined conversion here, so probably not.


================
Comment at: clang/lib/Sema/SemaOverload.cpp:10465-10473
-    } else if (ToTy->isLValueReferenceType() && !FromExpr->isLValue() &&
-               ToTy.getNonReferenceType().getCanonicalType() ==
-               FromTy.getNonReferenceType().getCanonicalType()) {
-      S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_lvalue)
-          << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << FnDesc
-          << (unsigned)isObjectArgument << I + 1
-          << (FromExpr ? FromExpr->getSourceRange() : SourceRange());
----------------
We are in the middle of an if-else cascade that is only setting `BaseToDerivedConversion`, where I think this doesn't belong. So I moved it directly after the qualifier mismatch handling.


================
Comment at: clang/test/SemaCXX/overload-member-call.cpp:86-87
 
+    void ref() &&;   // expected-note {{expects an r-value for object argument}} expected-note {{requires 0 arguments, but 1 was provided}}
+    void ref(int) &; // expected-note {{expects an l-value for object argument}} expected-note {{requires 1 argument, but 0 were provided}}
+
----------------
The respective first note was "no known conversion from 'test1::A' to 'test1::A' for object argument", which is silly.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90123/new/

https://reviews.llvm.org/D90123



More information about the cfe-commits mailing list