diff options
| author | Anders Carlsson <andersca@mac.com> | 2009-10-09 23:51:55 +0000 |
|---|---|---|
| committer | Anders Carlsson <andersca@mac.com> | 2009-10-09 23:51:55 +0000 |
| commit | 7f84ed928721b49670024fd711ebbc276f038992 (patch) | |
| tree | d9c29ffb53a7af9d7f23dababeae2caf10c93f9a /clang/lib | |
| parent | 918ec53c647f13885cf05d71845e325725d2d2f7 (diff) | |
| download | bcm5719-llvm-7f84ed928721b49670024fd711ebbc276f038992.tar.gz bcm5719-llvm-7f84ed928721b49670024fd711ebbc276f038992.zip | |
Add CheckCallReturnType and start using it for regular call expressions. This will improve error messages. For
struct B;
B f();
void g() {
f();
}
We now get
t.cpp:6:3: error: calling 'f' with incomplete return type 'struct B'
f();
^~~
t.cpp:3:3: note: 'f' declared here
B f();
^
t.cpp:1:8: note: forward declaration of 'struct B'
struct B;
^
llvm-svn: 83692
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/Sema.h | 11 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 31 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaOverload.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaType.cpp | 8 |
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; |

