I like to make use of most of the warnings gcc can provide - they can often
give a good indication of small mistakes in the code (trapping things like
if (x = 1) ... and other common mistakes).  The -Wunreachable-code is
particularly useful.  However, this seems to work badly with optomisation.
In the code:

int a, b;

void t2(void) {
 switch (a) {
  case 1 : b = 1; break;
  case 2 : b = 2; break;
  case 3 : b = 1; break;
 };
}

When optomisation is turned on (-O or above), only one "b = 1" statement is
actually generated, and the code jumps there for either case 1 or case 3.
This is, of course, good optomisation, and is particularly useful for more
complex cases.  However, the compiler gives a "warning: will never be
executed" warning on the line "case 1..." .  The duplicate code has been
eliminated, but the line itself will still be executed - the warning here is
incorrect.  Is this an mspgcc issue, or a general gcc issue?  The generated
code works perfectly, whether compiled with optomisation or not, but it
would be nice to avoid incorrect warnings, while keeping the warnings when
they really are valid.

mvh.

David



Reply via email to