summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-01-07 02:04:15 +0000
committerJohn McCall <rjmccall@apple.com>2010-01-07 02:04:15 +0000
commit0237485287e9b30a811ac79264d84acabae77895 (patch)
treee4cbe677d18932df4bb79af646c9d3065a133d6b /clang/lib/Sema
parent9855a6bb7c6f4ff756d6aa19e9561364340c3880 (diff)
downloadbcm5719-llvm-0237485287e9b30a811ac79264d84acabae77895.tar.gz
bcm5719-llvm-0237485287e9b30a811ac79264d84acabae77895.zip
Improve the lead diagnostic for C++ object subscript expressions with
no viable overloads. Use a different message when the class provides no operator[] overloads at all; use it for operator(), too. Partially addresses PR 5900. llvm-svn: 92894
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaOverload.cpp32
1 files changed, 19 insertions, 13 deletions
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index cec167953c8..d2bd4eea98f 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -5449,16 +5449,17 @@ Sema::CreateOverloadedArraySubscriptExpr(SourceLocation LLoc,
}
case OR_No_Viable_Function: {
- // No viable function; try to create a built-in operation, which will
- // produce an error. Then, show the non-viable candidates.
- OwningExprResult Result =
- CreateBuiltinArraySubscriptExpr(move(Base), LLoc, move(Idx), RLoc);
- assert(Result.isInvalid() &&
- "C++ subscript operator overloading is missing candidates!");
- if (Result.isInvalid())
- PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false,
- "[]", LLoc);
- return move(Result);
+ if (CandidateSet.empty())
+ Diag(LLoc, diag::err_ovl_no_oper)
+ << Args[0]->getType() << /*subscript*/ 0
+ << Args[0]->getSourceRange() << Args[1]->getSourceRange();
+ else
+ Diag(LLoc, diag::err_ovl_no_viable_subscript)
+ << Args[0]->getType()
+ << Args[0]->getSourceRange() << Args[1]->getSourceRange();
+ PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false,
+ "[]", LLoc);
+ return ExprError();
}
case OR_Ambiguous:
@@ -5712,9 +5713,14 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
break;
case OR_No_Viable_Function:
- Diag(Object->getSourceRange().getBegin(),
- diag::err_ovl_no_viable_object_call)
- << Object->getType() << Object->getSourceRange();
+ if (CandidateSet.empty())
+ Diag(Object->getSourceRange().getBegin(), diag::err_ovl_no_oper)
+ << Object->getType() << /*call*/ 1
+ << Object->getSourceRange();
+ else
+ Diag(Object->getSourceRange().getBegin(),
+ diag::err_ovl_no_viable_object_call)
+ << Object->getType() << Object->getSourceRange();
PrintOverloadCandidates(CandidateSet, /*OnlyViable=*/false);
break;
OpenPOWER on IntegriCloud