Xcode offers strange solution for explicitly dead code in c++? -


i'm writing program supposed solve sudoko-like puzzle, hashiwokakero. have code looks this:

if (bridgesleft[row][col] == 1) {    dosomething(); } else if (bridgesleft[row][col] == 2) {    dosomethingelse(); } else if (bridgesleft[row][col] == 3) {    doanotherthing(); } ... 

i realized put bug in dosomethingelse() function, rather deleting block, added else if (bridgesleft[row][col] == 2 && false) guarantee buggy function wouldn't run, make sure bug coming from. xcode gave me warning, saying dosomethingelse() code never run. gave me option:

fix-it: silence adding parentheses mark code explicitly dead. 

clicking on button changes

else if (bridgesleft[row][col] == 2 && false) 

to

else if (bridgesleft[row][col] == /* disables code */ (2) && false) 

how parentheses around '2' mark code explicitly dead? mean? if leave parentheses in, take && false part out, code block still executed, it's not making code dead.

this not fix problem as silence warning telling clang code meant dead, can see reading improve -wunreachable-code provide means indicate code intentionally marked dead via if((0)) says:

log: improve -wunreachable-code provide means indicate code intentionally marked dead via if((0)).

taking hint -wparentheses, use '()' sigil dead condition intentionally dead. example:

if ((0)) { dead } 

when sigil found, not emit dead code warning. when analysis sees:

if (0) 

it suggests inserting '()' fix-it.

from can tell looking integer literal in (), in case (2) fits case , silences warning.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -