My custom assertion preprocessor macros trigger ‘Assuming ‘variable’ is equal to nil’ and ‘Null pointer passed as an argument to a 'nonnull' parameter’ compiler warnings during an Analyze Build with Xcode 6.4 if the value being checked is later in the test code passed to a function whose parameter cannot be NULL. These assertion preprocessor macros expand to an if statement which checks the condition and fail if the condition is not met.
e.g. - The macros are defined something along the lines of this.
#include <xpc/xpc.h>
#define ShouldBeTrue(condition_MacroParam, format_string_MacroParam, ...) \
do { \
if (!(condition_MacroParam)) { \
} \
} while(0)An example call which triggers the warning:
const char *machServiceIdentifier = "com.test.XPCLA";
xpc_connection_t connection = xpc_connection_create_mach_service(machServiceIdentifier, NULL, 0);
ShouldBeTrue(connection != NULL, @"Connection to %s should not be NULL", machServiceIdentifier); // <-- 'Assuming 'connection' is equal to null'
xpc_connection_set_event_handler(connection, ^(xpc_object_t object) {});If I instead use Cocoa's NSAssert() or XCTest’s XCTAssert() macros this compiler warning does not occur. How do Apple’s assertion macros manage to avoid this kind of warning?