[cfe-commits] r158691 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaOverload.cpp test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp test/Misc/integer-literal-printing.cpp test/SemaCXX/user-defined-conversio

Eli Friedman eli.friedman at gmail.com
Mon Jun 18 18:43:44 PDT 2012


On Mon, Jun 18, 2012 at 5:37 PM, Kaelyn Uhrain <rikka at google.com> wrote:
> Author: rikka
> Date: Mon Jun 18 19:37:47 2012
> New Revision: 158691
>
> URL: http://llvm.org/viewvc/llvm-project?rev=158691&view=rev
> Log:
> Improve the error message when a function overload candidate is rejected
> because it expects a reference and receives a non-l-value.
>
> For example, given:
>
>  int foo(int &);
>  template<int x> void b() { foo(x); }
>
> clang will now print "expects an l-value for 1st argument" instead of
> "no known conversion from 'int' to 'int &' for 1st argument". The change
> in wording (and associated code to detect the case) was prompted by
> comment #5 in PR3104, and should be the last bit of work needed for the
> bug.
>
> Modified:
>    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>    cfe/trunk/lib/Sema/SemaOverload.cpp
>    cfe/trunk/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp
>    cfe/trunk/test/Misc/integer-literal-printing.cpp
>    cfe/trunk/test/SemaCXX/user-defined-conversions.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=158691&r1=158690&r2=158691&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jun 18 19:37:47 2012
> @@ -2163,6 +2163,17 @@
>     "constructor (inherited)}0%1"
>     " not viable: cannot implicitly convert argument of type %2 to %3 for "
>     "%select{%ordinal5 argument|object argument}4 under ARC">;
> +def note_ovl_candidate_bad_lvalue : Note<"candidate "
> +    "%select{function|function|constructor|"
> +    "function |function |constructor |"
> +    "constructor (the implicit default constructor)|"
> +    "constructor (the implicit copy constructor)|"
> +    "constructor (the implicit move constructor)|"
> +    "function (the implicit copy assignment operator)|"
> +    "function (the implicit move assignment operator)|"
> +    "constructor (inherited)}0%1"
> +    " not viable: expects an l-value for "
> +    "%select{%ordinal3 argument|object argument}2">;
>  def note_ovl_candidate_bad_addrspace : Note<"candidate "
>     "%select{function|function|constructor|"
>     "function |function |constructor |"
>
> Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=158691&r1=158690&r2=158691&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaOverload.cpp Mon Jun 18 19:37:47 2012
> @@ -8153,12 +8153,27 @@
>               FromIface->isSuperClassOf(ToIface))
>             BaseToDerivedConversion = 2;
>   } else if (const ReferenceType *ToRefTy = ToTy->getAs<ReferenceType>()) {
> -      if (ToRefTy->getPointeeType().isAtLeastAsQualifiedAs(FromTy) &&
> -          !FromTy->isIncompleteType() &&
> -          !ToRefTy->getPointeeType()->isIncompleteType() &&
> -          S.IsDerivedFrom(ToRefTy->getPointeeType(), FromTy))
> -        BaseToDerivedConversion = 3;
> +    if (ToRefTy->getPointeeType().isAtLeastAsQualifiedAs(FromTy) &&
> +        !FromTy->isIncompleteType() &&
> +        !ToRefTy->getPointeeType()->isIncompleteType() &&
> +        S.IsDerivedFrom(ToRefTy->getPointeeType(), FromTy)) {
> +      BaseToDerivedConversion = 3;
> +    } else if (ToTy->isLValueReferenceType() && !FromExpr->isLValue() &&
> +               ToTy.getNonReferenceType().getCanonicalType() ==
> +               FromTy.getNonReferenceType().getCanonicalType()) {
> +      QualType T1 = ToTy.getCanonicalType();
> +      QualType T2 = ToTy.getNonReferenceType();
> +      QualType T3 = T2.getUnqualifiedType();
> +      QualType T4 = FromTy.getCanonicalType();
> +      (void)T1; (void)T2; (void)T3; (void)T4;

Leftover debugging code?

-Eli




More information about the cfe-commits mailing list