r189510 - Improve error for assignment to incomplete class.

Richard Smith richard at metafoo.co.uk
Wed Aug 28 14:54:45 PDT 2013


On Wed, Aug 28, 2013 at 1:35 PM, Eli Friedman <eli.friedman at gmail.com>wrote:

> Author: efriedma
> Date: Wed Aug 28 15:35:35 2013
> New Revision: 189510
>
> URL: http://llvm.org/viewvc/llvm-project?rev=189510&view=rev
> Log:
> Improve error for assignment to incomplete class.
>
> PR7681.
>
> Modified:
>     cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>     cfe/trunk/lib/Sema/SemaOverload.cpp
>     cfe/trunk/test/SemaCXX/overloaded-operator.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=189510&r1=189509&r2=189510&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Aug 28
> 15:35:35 2013
> @@ -2752,6 +2752,7 @@ def err_ovl_ambiguous_oper_unary : Error
>  def err_ovl_ambiguous_oper_binary : Error<
>    "use of overloaded operator '%0' is ambiguous (with operand types %1
> and %2)">;
>  def err_ovl_no_viable_oper : Error<"no viable overloaded '%0'">;
> +def note_assign_lhs_incomplete : Note<"type %0 is incomplete">;
>  def err_ovl_deleted_oper : Error<
>    "overload resolution selected %select{unavailable|deleted}0 operator
> '%1'%2">;
>  def err_ovl_deleted_special_oper : Error<
>
> Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=189510&r1=189509&r2=189510&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Aug 28 15:35:35 2013
> @@ -10714,6 +10714,11 @@ Sema::CreateOverloadedBinOp(SourceLocati
>          Diag(OpLoc,  diag::err_ovl_no_viable_oper)
>               << BinaryOperator::getOpcodeStr(Opc)
>               << Args[0]->getSourceRange() << Args[1]->getSourceRange();
> +        if (Args[0]->getType()->isIncompleteType()) {
> +          Diag(OpLoc, diag::note_assign_lhs_incomplete)
> +            << Args[0]->getType()
> +            << Args[0]->getSourceRange() << Args[1]->getSourceRange();
> +        }
>

Is there a reason to not use RequireCompleteType here? It'd be nice to at
least point the note at the forward declaration of the class rather than at
the '='.


>        } else {
>          // This is an erroneous use of an operator which can be
> overloaded by
>          // a non-member function. Check for non-member operators which
> were
>
> Modified: cfe/trunk/test/SemaCXX/overloaded-operator.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overloaded-operator.cpp?rev=189510&r1=189509&r2=189510&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/overloaded-operator.cpp (original)
> +++ cfe/trunk/test/SemaCXX/overloaded-operator.cpp Wed Aug 28 15:35:35 2013
> @@ -445,3 +445,10 @@ namespace test10 {
>  struct InvalidOperatorEquals {
>    InvalidOperatorEquals operator=() = delete; // expected-error
> {{overloaded 'operator=' must be a binary operator}}
>  };
> +
> +namespace PR7681 {
> +  template <typename PT1, typename PT2> class PointerUnion;
> +  void foo(PointerUnion<int*, float*> &Result) {
> +    Result = 1; // expected-error {{no viable overloaded '='}} //
> expected-note {{type 'PointerUnion<int *, float *>' is incomplete}}
> +  }
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130828/18325617/attachment.html>


More information about the cfe-commits mailing list