[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:
parent
bd1716aed1
commit
8dad0e6cce
|
@ -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),
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue