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 | bc8d42c6f1565c0b2f93ad524edebfd7a4e6cac6 (patch) | |
tree | 125ce2d07d181ed1f49f80244a64028b34427a6a /lib/Sema | |
parent | 4053983963cb94a6129da47bca8cce637c8b7bff (diff) |
make the diagnostic in the 'unused result' warning more precise
about the reason, rdar://7186119.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83940 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 2a3b9eeea8..e8cd6b081d 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/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; } |