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/Sema/SemaExpr.cpp | |
| 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/Sema/SemaExpr.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 31 |
1 files changed, 26 insertions, 5 deletions
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; +} + |

