summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/Sema.h11
-rw-r--r--clang/lib/Sema/SemaExpr.cpp31
-rw-r--r--clang/lib/Sema/SemaOverload.cpp8
-rw-r--r--clang/lib/Sema/SemaType.cpp8
4 files changed, 47 insertions, 11 deletions
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h
index 33d7468787d..6c9466f8639 100644
--- a/clang/lib/Sema/Sema.h
+++ b/clang/lib/Sema/Sema.h
@@ -493,7 +493,10 @@ public:
virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
bool RequireCompleteType(SourceLocation Loc, QualType T,
- const PartialDiagnostic &PD);
+ const PartialDiagnostic &PD,
+ std::pair<SourceLocation,
+ PartialDiagnostic> Note =
+ std::make_pair(SourceLocation(), PDiag()));
QualType getQualifiedNameType(const CXXScopeSpec &SS, QualType T);
@@ -959,6 +962,12 @@ public:
OwningExprResult BuildOverloadedArrowExpr(Scope *S, ExprArg Base,
SourceLocation OpLoc);
+ /// CheckCallReturnType - Checks that a call expression's return type is
+ /// complete. Returns true on failure. The location passed in is the location
+ /// that best represents the call.
+ bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
+ CallExpr *CE, FunctionDecl *FD);
+
/// Helpers for dealing with blocks and functions.
void CheckFallThroughForFunctionDef(Decl *D, Stmt *Body);
void CheckFallThroughForBlock(QualType BlockTy, Stmt *Body);
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index b4384b11fdc..9831fba3190 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3013,11 +3013,9 @@ Sema::ActOnCallExpr(Scope *S, ExprArg fn, SourceLocation LParenLoc,
<< Fn->getType() << Fn->getSourceRange());
// Check for a valid return type
- if (!FuncT->getResultType()->isVoidType() &&
- RequireCompleteType(Fn->getSourceRange().getBegin(),
- FuncT->getResultType(),
- PDiag(diag::err_call_incomplete_return)
- << TheCall->getSourceRange()))
+ if (CheckCallReturnType(FuncT->getResultType(),
+ Fn->getSourceRange().getBegin(), TheCall.get(),
+ FDecl))
return ExprError();
// We know the result type of the call, set it.
@@ -6223,3 +6221,26 @@ void Sema::MarkDeclarationReferenced(SourceLocation Loc, Decl *D) {
return;
}
}
+
+bool Sema::CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
+ CallExpr *CE, FunctionDecl *FD) {
+ if (ReturnType->isVoidType() || !ReturnType->isIncompleteType())
+ return false;
+
+ PartialDiagnostic Note =
+ FD ? PDiag(diag::note_function_with_incomplete_return_type_declared_here)
+ << FD->getDeclName() : PDiag();
+ SourceLocation NoteLoc = FD ? FD->getLocation() : SourceLocation();
+
+ if (RequireCompleteType(Loc, ReturnType,
+ FD ?
+ PDiag(diag::err_call_function_incomplete_return)
+ << CE->getSourceRange() << FD->getDeclName() :
+ PDiag(diag::err_call_incomplete_return)
+ << CE->getSourceRange(),
+ std::make_pair(NoteLoc, Note)))
+ return true;
+
+ return false;
+}
+
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 04568a5d3af..9615a3cf57d 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2759,7 +2759,7 @@ void Sema::AddMemberOperatorCandidates(OverloadedOperatorKind Op,
// empty.
if (const RecordType *T1Rec = T1->getAs<RecordType>()) {
// Complete the type if it can be completed. Otherwise, we're done.
- if (RequireCompleteType(OpLoc, T1, PartialDiagnostic(0)))
+ if (RequireCompleteType(OpLoc, T1, PDiag()))
return;
LookupResult Operators;
@@ -4219,10 +4219,10 @@ Sema::ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
Matches.end());
return getMostSpecialized(TemplateMatches.data(), TemplateMatches.size(),
TPOC_Other, From->getLocStart(),
- PartialDiagnostic(0),
- PartialDiagnostic(diag::err_addr_ovl_ambiguous)
+ PDiag(),
+ PDiag(diag::err_addr_ovl_ambiguous)
<< TemplateMatches[0]->getDeclName(),
- PartialDiagnostic(diag::err_ovl_template_candidate));
+ PDiag(diag::err_ovl_template_candidate));
}
// [...] any function template specializations in the set are
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index da72197f0ca..67677120858 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1820,7 +1820,9 @@ void Sema::ProcessTypeAttributeList(QualType &Result, const AttributeList *AL) {
/// @returns @c true if @p T is incomplete and a diagnostic was emitted,
/// @c false otherwise.
bool Sema::RequireCompleteType(SourceLocation Loc, QualType T,
- const PartialDiagnostic &PD) {
+ const PartialDiagnostic &PD,
+ std::pair<SourceLocation,
+ PartialDiagnostic> Note) {
unsigned diag = PD.getDiagID();
// FIXME: Add this assertion to help us flush out problems with
@@ -1864,6 +1866,10 @@ bool Sema::RequireCompleteType(SourceLocation Loc, QualType T,
// We have an incomplete type. Produce a diagnostic.
Diag(Loc, PD) << T;
+ // If we have a note, produce it.
+ if (!Note.first.isInvalid())
+ Diag(Note.first, Note.second);
+
// If the type was a forward declaration of a class/struct/union
// type, produce
const TagType *Tag = 0;
OpenPOWER on IntegriCloud