diff options
author | Chris Lattner <sabre@nondot.org> | 2009-10-13 04:53:48 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-10-13 04:53:48 +0000 |
commit | 1a6babf1f41c3c8d6a0dab98e02b7caaf9024da6 (patch) | |
tree | 7767d9db3b1ddf4f4685937d21c0295e7f019f75 /clang/lib/Sema/SemaStmt.cpp | |
parent | f315471e24305ee3c63960edca252ac91da5ee4a (diff) | |
download | bcm5719-llvm-1a6babf1f41c3c8d6a0dab98e02b7caaf9024da6.tar.gz bcm5719-llvm-1a6babf1f41c3c8d6a0dab98e02b7caaf9024da6.zip |
make the diagnostic in the 'unused result' warning more precise
about the reason, rdar://7186119.
llvm-svn: 83940
Diffstat (limited to 'clang/lib/Sema/SemaStmt.cpp')
-rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 2a3b9eeea81..e8cd6b081de 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -80,6 +80,25 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S) { E = E->IgnoreParens(); if (isa<ObjCImplicitSetterGetterRefExpr>(E)) DiagID = diag::warn_unused_property_expr; + + if (const CallExpr *CE = dyn_cast<CallExpr>(E)) { + // If the callee has attribute pure, const, or warn_unused_result, warn with + // a more specific message to make it clear what is happening. + if (const FunctionDecl *FD = CE->getDirectCallee()) { + if (FD->getAttr<WarnUnusedResultAttr>()) { + Diag(Loc, diag::warn_unused_call) << R1 << R2 << "warn_unused_result"; + return; + } + if (FD->getAttr<PureAttr>()) { + Diag(Loc, diag::warn_unused_call) << R1 << R2 << "pure"; + return; + } + if (FD->getAttr<ConstAttr>()) { + Diag(Loc, diag::warn_unused_call) << R1 << R2 << "const"; + return; + } + } + } Diag(Loc, DiagID) << R1 << R2; } |