[analyzer] Don't throw NSNumberObjectConversion warning on object initialization in if-expression

```
if (NSNumber* x = ...)
```
is a reasonable pattern in objc++, we should not warn on it.

rdar://35152234

Differential Revision: https://reviews.llvm.org/D44044

llvm-svn: 326619
This commit is contained in:
George Karpenkov 2018-03-02 21:34:24 +00:00
parent bd1716aed1
commit 8dad0e6cce
2 changed files with 17 additions and 2 deletions

View File

@ -270,8 +270,10 @@ void NumberObjectConversionChecker::checkASTCodeBody(const Decl *D,
hasRHS(SuspiciousNumberObjectExprM)));
auto ConversionThroughBranchingM =
ifStmt(hasCondition(SuspiciousNumberObjectExprM))
.bind("pedantic");
ifStmt(allOf(
hasCondition(SuspiciousNumberObjectExprM),
unless(hasConditionVariableStatement(declStmt())
))).bind("pedantic");
auto ConversionThroughCallM =
callExpr(hasAnyArgument(allOf(hasType(SuspiciousScalarTypeM),

View File

@ -0,0 +1,13 @@
// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -fblocks -fobjc-arc -w -analyzer-checker=osx.NumberObjectConversion -analyzer-config osx.NumberObjectConversion:Pedantic=true %s -verify
#include "Inputs/system-header-simulator-objc.h"
NSNumber* generateNumber();
// expected-no-diagnostics
int test_initialization_in_ifstmt() { // Don't warn on initialization in guard.
if (NSNumber* number = generateNumber()) { // no-warning
return 0;
}
return 1;
}