"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">;
#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"
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