The return operation will never be completed.

Recently, I came across a double return (one of them was added by mistake) in our project and wondered why the compiler does not display a warning for this ?!

Ok, I added -Wunreachable-code to the other warning flags, but still no luck.

Get a warning - with code to execute after return :

enter image description here

I did not receive a warning, but the second return will never be executed. enter image description here

Even if I add something like this, still no warnings

enter image description here

Is there an extra warning flag for this, or is the compiler not smart enough?

+6
source share
3 answers

Good booty!

-Wunreachable-code does not report a warning, and there is no other warning flag that would do.
Even a static analyzer will not catch this error!

(Tested with Xcode 6.1 GM 2)

+2
source

Use -Wno-unreachable-code for your file during build steps.

0
source

Try it...

 -(NSString*) makeSomeStringForMe { NSString *someString = @"some string"; return someString; } 
-1
source

Source: https://habr.com/ru/post/976413/


All Articles