XCTAssert behaves as return statement

Originator:green
Number:rdar://22350813 Date Originated:19-Aug-2015
Status:Open Resolved:
Product:Xcode Product Version:6.4
Classification: Reproducible:Always
 
Summary:
XCTAssert acts as a return statement when it is the last statement in a block returning a BOOL. XCTAssert does not return a value so it should not be a valid result of a non-void function. I suspect this is caused by the XCTAssert{...} macros being implemented as @try/@catch in a compound statement.

I ran into this bug when I was writing unit tests with the OCMock library. The unit tests was failing in -[OCMArg checkWithBlock:] even thought all the asserts passed because I had forgotten to write "return YES;" in one block.

Steps to Reproduce:
Run the unit tests of the attached project.

Expected Results:
Blocks ending with XCTAssert{...} should refuse to compile with the error "Control reaches end of non-void block".

Actual Results:
The block compiles without any return statement.

Version:
Xcode 6.4 w/ iPhone 6 (iOS 8.4) simulator

Notes:


Configuration:


Attachments:
'NoReturn.zip' was successfully uploaded.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!