[cfe-commits] r79192 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaStmt.cpp test/SemaObjC/unused.m
Chris Lattner
sabre at nondot.org
Sun Aug 16 09:57:27 PDT 2009
Author: lattner
Date: Sun Aug 16 11:57:27 2009
New Revision: 79192
URL: http://llvm.org/viewvc/llvm-project?rev=79192&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/SemaObjC/unused.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=79192&r1=79191&r2=79192&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Aug 16 11:57:27 2009
@@ -1687,6 +1687,9 @@
"expression is not a constant, but is accepted as one by GNU extensions">;
def warn_unused_expr : Warning<"expression result unused">,
InGroup<UnusedValue>;
+def warn_unused_property_expr : Warning<
+ "property access result unused - getters should not have side effects">,
+ InGroup<UnusedValue>;
def err_incomplete_type_used_in_type_trait_expr : Error<
"incomplete type %0 used in type trait expression">;
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=79192&r1=79191&r2=79192&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sun Aug 16 11:57:27 2009
@@ -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 @@
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
Modified: cfe/trunk/test/SemaObjC/unused.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/unused.m?rev=79192&r1=79191&r2=79192&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/unused.m (original)
+++ cfe/trunk/test/SemaObjC/unused.m Sun Aug 16 11:57:27 2009
@@ -25,7 +25,7 @@
@end
void test2() {
- @"pointless example call for test purposes".length; // expected-warning {{expression result unused}}
+ @"pointless example call for test purposes".length; // expected-warning {{property access result unused - getters should not have side effects}}
}
More information about the cfe-commits
mailing list