Skip to content

Commit 99c8dd1

Browse files
committed
[Clang] Handle remaining diagnostics
1 parent 3445e48 commit 99c8dd1

File tree

5 files changed

+270
-24
lines changed

5 files changed

+270
-24
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4908,12 +4908,12 @@ def err_ovl_ambiguous_conversion_in_cast : Error<
49084908
"dynamic_cast|C-style cast|functional-style cast|}0 from %1 to %2">;
49094909
def err_ovl_deleted_conversion_in_cast : Error<
49104910
"%select{|static_cast|reinterpret_cast|dynamic_cast|C-style cast|"
4911-
"functional-style cast|}0 from %1 to %2 uses deleted function">;
4911+
"functional-style cast|}0 from %1 to %2 uses deleted function%select{|: %4}3">;
49124912
def err_ovl_ambiguous_init : Error<"call to constructor of %0 is ambiguous">;
49134913
def err_ref_init_ambiguous : Error<
49144914
"reference initialization of type %0 with initializer of type %1 is ambiguous">;
49154915
def err_ovl_deleted_init : Error<
4916-
"call to deleted constructor of %0">;
4916+
"call to deleted constructor of %0%select{|: %2}1">;
49174917
def err_ovl_deleted_special_init : Error<
49184918
"call to implicitly-deleted %select{default constructor|copy constructor|"
49194919
"move constructor|copy assignment operator|move assignment operator|"
@@ -4939,7 +4939,7 @@ def note_ovl_ambiguous_oper_binary_reversed_candidate : Note<
49394939
def err_ovl_no_viable_oper : Error<"no viable overloaded '%0'">;
49404940
def note_assign_lhs_incomplete : Note<"type %0 is incomplete">;
49414941
def err_ovl_deleted_oper : Error<
4942-
"overload resolution selected deleted operator '%0'">;
4942+
"overload resolution selected deleted operator '%0'%select{|: %2}1">;
49434943
def err_ovl_deleted_special_oper : Error<
49444944
"object of type %0 cannot be %select{constructed|copied|moved|assigned|"
49454945
"assigned|destroyed}1 because its %sub{select_special_member_kind}1 is "
@@ -4976,7 +4976,7 @@ def err_ovl_ambiguous_object_call : Error<
49764976
def err_ovl_ambiguous_subscript_call : Error<
49774977
"call to subscript operator of type %0 is ambiguous">;
49784978
def err_ovl_deleted_object_call : Error<
4979-
"call to deleted function call operator in type %0">;
4979+
"call to deleted function call operator in type %0%select{|: %2}1">;
49804980
def note_ovl_surrogate_cand : Note<"conversion candidate of type %0">;
49814981
def err_member_call_without_object : Error<
49824982
"call to %select{non-static|explicit}0 member function without an object argument">;
@@ -8276,7 +8276,7 @@ def err_typecheck_nonviable_condition_incomplete : Error<
82768276
"no viable conversion%diff{ from $ to incomplete type $|}0,1">;
82778277
def err_typecheck_deleted_function : Error<
82788278
"conversion function %diff{from $ to $|between types}0,1 "
8279-
"invokes a deleted function">;
8279+
"invokes a deleted function%select{|: %3}2">;
82808280

82818281
def err_expected_class_or_namespace : Error<"%0 is not a class"
82828282
"%select{ or namespace|, namespace, or enumeration}1">;

clang/lib/Sema/SemaCast.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,22 @@ static bool tryDiagnoseOverloadedCast(Sema &S, CastType CT,
498498
howManyCandidates = OCD_AmbiguousCandidates;
499499
break;
500500

501-
case OR_Deleted:
502-
msg = diag::err_ovl_deleted_conversion_in_cast;
503-
howManyCandidates = OCD_ViableCandidates;
504-
break;
501+
case OR_Deleted: {
502+
OverloadCandidateSet::iterator Best;
503+
OverloadingResult Res =
504+
candidates.BestViableFunction(S, range.getBegin(), Best);
505+
assert(Res == OR_Deleted && "Inconsistent overload resolution");
506+
507+
StringLiteral *Msg = Best->Function->getDeletedMessage();
508+
candidates.NoteCandidates(
509+
PartialDiagnosticAt(range.getBegin(),
510+
S.PDiag(diag::err_ovl_deleted_conversion_in_cast)
511+
<< CT << srcType << destType << !!Msg
512+
<< (Msg ? Msg->getString() : StringRef())
513+
<< range << src->getSourceRange()),
514+
S, OCD_ViableCandidates, src);
515+
return true;
516+
}
505517
}
506518

507519
candidates.NoteCandidates(

clang/lib/Sema/SemaInit.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9762,12 +9762,15 @@ bool InitializationSequence::Diagnose(Sema &S,
97629762
break;
97639763
}
97649764
case OR_Deleted: {
9765-
S.Diag(Kind.getLocation(), diag::err_typecheck_deleted_function)
9766-
<< OnlyArg->getType() << DestType.getNonReferenceType()
9767-
<< Args[0]->getSourceRange();
97689765
OverloadCandidateSet::iterator Best;
97699766
OverloadingResult Ovl
97709767
= FailedCandidateSet.BestViableFunction(S, Kind.getLocation(), Best);
9768+
9769+
StringLiteral *Msg = Best->Function->getDeletedMessage();
9770+
S.Diag(Kind.getLocation(), diag::err_typecheck_deleted_function)
9771+
<< OnlyArg->getType() << DestType.getNonReferenceType() << !!Msg
9772+
<< (Msg ? Msg->getString() : StringRef())
9773+
<< Args[0]->getSourceRange();
97719774
if (Ovl == OR_Deleted) {
97729775
S.NoteDeletedFunction(Best->Function);
97739776
} else {
@@ -10025,9 +10028,12 @@ bool InitializationSequence::Diagnose(Sema &S,
1002510028
S.Diag(Kind.getLocation(), diag::err_ovl_deleted_special_init)
1002610029
<< S.getSpecialMember(cast<CXXMethodDecl>(Best->Function))
1002710030
<< DestType << ArgsRange;
10028-
else
10031+
else {
10032+
StringLiteral *Msg = Best->Function->getDeletedMessage();
1002910033
S.Diag(Kind.getLocation(), diag::err_ovl_deleted_init)
10030-
<< DestType << ArgsRange;
10034+
<< DestType << !!Msg << (Msg ? Msg->getString() : StringRef())
10035+
<< ArgsRange;
10036+
}
1003110037

1003210038
S.NoteDeletedFunction(Best->Function);
1003310039
break;
@@ -11075,6 +11081,9 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer(
1107511081
}
1107611082

1107711083
case OR_Deleted: {
11084+
// FIXME: There are no tests for this diagnostic, and it doesn't seem
11085+
// like we ever get here; attempts to trigger this seem to yield a
11086+
// generic c'all to deleted function' diagnostic instead.
1107811087
Diag(Kind.getLocation(), diag::err_deduced_class_template_deleted)
1107911088
<< TemplateName;
1108011089
NoteDeletedFunction(Best->Function);

clang/lib/Sema/SemaOverload.cpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14525,20 +14525,24 @@ Sema::CreateOverloadedUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc,
1452514525
UnaryOperator::getOpcodeStr(Opc), OpLoc);
1452614526
return ExprError();
1452714527

14528-
case OR_Deleted:
14528+
case OR_Deleted: {
1452914529
// CreateOverloadedUnaryOp fills the first element of ArgsArray with the
1453014530
// object whose method was called. Later in NoteCandidates size of ArgsArray
1453114531
// is passed further and it eventually ends up compared to number of
1453214532
// function candidate parameters which never includes the object parameter,
1453314533
// so slice ArgsArray to make sure apples are compared to apples.
14534+
StringLiteral *Msg = Best->Function->getDeletedMessage();
1453414535
CandidateSet.NoteCandidates(
1453514536
PartialDiagnosticAt(OpLoc, PDiag(diag::err_ovl_deleted_oper)
1453614537
<< UnaryOperator::getOpcodeStr(Opc)
14538+
<< !!Msg
14539+
<< (Msg ? Msg->getString() : StringRef())
1453714540
<< Input->getSourceRange()),
1453814541
*this, OCD_AllCandidates, ArgsArray.drop_front(),
1453914542
UnaryOperator::getOpcodeStr(Opc), OpLoc);
1454014543
return ExprError();
1454114544
}
14545+
}
1454214546

1454314547
// Either we found no viable overloaded operator or we matched a
1454414548
// built-in operator. In either case, fall through to trying to
@@ -15055,7 +15059,7 @@ ExprResult Sema::CreateOverloadedBinOp(SourceLocation OpLoc,
1505515059
OpLoc);
1505615060
return ExprError();
1505715061

15058-
case OR_Deleted:
15062+
case OR_Deleted: {
1505915063
if (isImplicitlyDeleted(Best->Function)) {
1506015064
FunctionDecl *DeletedFD = Best->Function;
1506115065
DefaultedFunctionKind DFK = getDefaultedFunctionKind(DeletedFD);
@@ -15073,16 +15077,20 @@ ExprResult Sema::CreateOverloadedBinOp(SourceLocation OpLoc,
1507315077
NoteDeletedFunction(DeletedFD);
1507415078
return ExprError();
1507515079
}
15080+
15081+
StringLiteral *Msg = Best->Function->getDeletedMessage();
1507615082
CandidateSet.NoteCandidates(
1507715083
PartialDiagnosticAt(
1507815084
OpLoc, PDiag(diag::err_ovl_deleted_oper)
1507915085
<< getOperatorSpelling(Best->Function->getDeclName()
1508015086
.getCXXOverloadedOperator())
15087+
<< !!Msg << (Msg ? Msg->getString() : StringRef())
1508115088
<< Args[0]->getSourceRange()
1508215089
<< Args[1]->getSourceRange()),
1508315090
*this, OCD_AllCandidates, Args, BinaryOperator::getOpcodeStr(Opc),
1508415091
OpLoc);
1508515092
return ExprError();
15093+
}
1508615094
}
1508715095

1508815096
// We matched a built-in operator; build it.
@@ -15394,14 +15402,18 @@ ExprResult Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
1539415402
}
1539515403
return ExprError();
1539615404

15397-
case OR_Deleted:
15405+
case OR_Deleted: {
15406+
StringLiteral *Msg = Best->Function->getDeletedMessage();
1539815407
CandidateSet.NoteCandidates(
15399-
PartialDiagnosticAt(LLoc, PDiag(diag::err_ovl_deleted_oper)
15400-
<< "[]" << Args[0]->getSourceRange()
15401-
<< Range),
15408+
PartialDiagnosticAt(LLoc,
15409+
PDiag(diag::err_ovl_deleted_oper)
15410+
<< "[]" << !!Msg
15411+
<< (Msg ? Msg->getString() : StringRef())
15412+
<< Args[0]->getSourceRange() << Range),
1540215413
*this, OCD_AllCandidates, Args, "[]", LLoc);
1540315414
return ExprError();
1540415415
}
15416+
}
1540515417

1540615418
// We matched a built-in operator; build it.
1540715419
return CreateBuiltinArraySubscriptExpr(Args[0], LLoc, Args[1], RLoc);
@@ -15881,15 +15893,21 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Obj,
1588115893
*this, OCD_AmbiguousCandidates, Args);
1588215894
break;
1588315895

15884-
case OR_Deleted:
15896+
case OR_Deleted: {
15897+
// FIXME: Is this diagnostic here really necessary? It seems that
15898+
// 1. we don't have any tests for this diagnostic, and
15899+
// 2. we already issue err_deleted_function_use for this later on anyway.
15900+
StringLiteral *Msg = Best->Function->getDeletedMessage();
1588515901
CandidateSet.NoteCandidates(
1588615902
PartialDiagnosticAt(Object.get()->getBeginLoc(),
1588715903
PDiag(diag::err_ovl_deleted_object_call)
15888-
<< Object.get()->getType()
15904+
<< Object.get()->getType() << !!Msg
15905+
<< (Msg ? Msg->getString() : StringRef())
1588915906
<< Object.get()->getSourceRange()),
1589015907
*this, OCD_AllCandidates, Args);
1589115908
break;
1589215909
}
15910+
}
1589315911

1589415912
if (Best == CandidateSet.end())
1589515913
return true;
@@ -16088,13 +16106,17 @@ Sema::BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc,
1608816106
*this, OCD_AmbiguousCandidates, Base);
1608916107
return ExprError();
1609016108

16091-
case OR_Deleted:
16109+
case OR_Deleted: {
16110+
StringLiteral *Msg = Best->Function->getDeletedMessage();
1609216111
CandidateSet.NoteCandidates(
1609316112
PartialDiagnosticAt(OpLoc, PDiag(diag::err_ovl_deleted_oper)
16094-
<< "->" << Base->getSourceRange()),
16113+
<< "->" << !!Msg
16114+
<< (Msg ? Msg->getString() : StringRef())
16115+
<< Base->getSourceRange()),
1609516116
*this, OCD_AllCandidates, Base);
1609616117
return ExprError();
1609716118
}
16119+
}
1609816120

1609916121
CheckMemberOperatorAccess(OpLoc, Base, nullptr, Best->FoundDecl);
1610016122

0 commit comments

Comments
 (0)