diff options
author | Chris Lattner <sabre@nondot.org> | 2009-08-16 16:57:27 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-08-16 16:57:27 +0000 |
commit | 2ba5ca9d4fd50309ea067e435c3d84a6718f69e3 (patch) | |
tree | a2cf987853fdf691537bc1d5026f2d3c8fb00586 /clang/lib/Sema/SemaStmt.cpp | |
parent | d37f61c1c6afbe606e952f3b058ddf481f4e603a (diff) | |
download | bcm5719-llvm-2ba5ca9d4fd50309ea067e435c3d84a6718f69e3.tar.gz bcm5719-llvm-2ba5ca9d4fd50309ea067e435c3d84a6718f69e3.zip |
Improve the diagnostic emitted when an unused ObjC property getter
is found. Instead of complaining about a generic "unused expr",
emit:
t.m:7:3: warning: property access result unused - getters should not have side effects
While objc property getters *could* have side effects, according to
the language best practices, they *shouldn't*. Hopefully the
diagnostic now gets this across.
llvm-svn: 79192
Diffstat (limited to 'clang/lib/Sema/SemaStmt.cpp')
-rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index f66ee1e30f2..579433849e6 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -15,7 +15,7 @@ #include "clang/AST/APValue.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclObjC.h" -#include "clang/AST/Expr.h" +#include "clang/AST/ExprObjC.h" #include "clang/AST/StmtObjC.h" #include "clang/AST/StmtCXX.h" #include "clang/Basic/TargetInfo.h" @@ -65,7 +65,15 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S) { if (!E->isUnusedResultAWarning(Loc, R1, R2)) return; - Diag(Loc, diag::warn_unused_expr) << R1 << R2; + // Okay, we have an unused result. Depending on what the base expression is, + // we might want to make a more specific diagnostic. Check for one of these + // cases now. + unsigned DiagID = diag::warn_unused_expr; + E = E->IgnoreParens(); + if (isa<ObjCKVCRefExpr>(E)) + DiagID = diag::warn_unused_property_expr; + + Diag(Loc, DiagID) << R1 << R2; } Action::OwningStmtResult |