ER: NSException’s raise… methods should have the `noreturn` attribute

Originator:daniel
Number:rdar://26725323 Date Originated:09-Jun-2016 12:59 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Any
Classification:Enhancement Reproducible:Always
 
Summary:
When writing Objective–C, you sometimes come across situations where a code path should never be triggered. The obvious thing to do here is to raise an exception.

When you’re implementing a method that has a non–void return type and this is a catch–all case you currently need to follow up a line like `[NSException raise:NSInternalInconsistencyException description:@"<why on earth this cannot possibly happen in a sane world>"];` with a nonsensical `return` statement, or a `__builtin_unreachable();`. None of these would be necessary if the `raise…` family was attributed as `noreturn`.

Steps to Reproduce:
1. write a function that returns some value based on its inputs where only some combinations of inputs make sense
1. after handling the valid combinations cover the catch–all by raising an exception

Expected Results:
Compiling the function with `-Werror-return-type` should succeed, even when there is no return statement after the `raise…` method.

Actual Results:
There is a compiler error because the compiler does not recognize that raising an exception breaks the control flow.

Regression:
does not apply

Notes:
Interestingly, the @throw directive is handled like `-raise`, `+raise:description:`, and `+raise:format:arguments:` should be.

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!