Improve error for assignment to incomplete class.

PR7681.

llvm-svn: 189510
This commit is contained in:
Eli Friedman 2013-08-28 20:35:35 +00:00
parent 22a351d314
commit a31efa07ff
3 changed files with 13 additions and 0 deletions

View File

@ -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<

View File

@ -10714,6 +10714,11 @@ Sema::CreateOverloadedBinOp(SourceLocation OpLoc,
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();
}
} 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

View File

@ -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}}
}
}