Author Topic: Fix "Unreachable code" warnings  (Read 1822 times)

0 Members and 1 Guest are viewing this topic.

Offline eipi

  • *
  • Posts: 67
  • Total likes: 5
  • Helpful: 12
  • Languages: DE EN FR ES C++ LaTeX
Fix "Unreachable code" warnings
« on: October 09, 2013, 08:42:20 AM »
Hi,

I made a patch to fix "unreachable code" warnings popping up in MSVC.
There are still some warnings, namely return statements after calls to dbg->fatal(). I did not touch them because I'm unsure whether removing them will trigger new warnings in gcc. (Don't have access to gcc atm so I can't test it.)

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8664
  • Total likes: 287
  • Helpful: 226
  • Languages: De,EN,JP
Re: Fix "Unreachable code" warnings
« Reply #1 on: October 09, 2013, 09:22:35 AM »
Some of those examples does not seem identical at first glance. You also mixed some reformatting into it.

On a different note: having a function to return a value at the end has been considered good practice (by some) in case the function is changed and will now reaches there.

If I do this I get some warnings that functions should return a value. I never got an unreachable code warning in MSVC so far. What kind of settings do you use? (If this is an MSVC 2012 warning, well the latest MSVC express does no longer install on XP.) So I will have to check it a home.

Offline eipi

  • *
  • Posts: 67
  • Total likes: 5
  • Helpful: 12
  • Languages: DE EN FR ES C++ LaTeX
Re: Fix "Unreachable code" warnings
« Reply #2 on: October 10, 2013, 09:33:46 AM »
If I do this I get some warnings that functions should return a value. I never got an unreachable code warning in MSVC so far. What kind of settings do you use? (If this is an MSVC 2012 warning, well the latest MSVC express does no longer install on XP.) So I will have to check it a home.

You can enable unreachable code messages by adding  /w3"4702" in Project Properties > C/C++ > Command Line. This will set the unreachable code warning to appear as a level 3 warning. The warning is disabled by default.