This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Implement -Wimplicit-fallthrough: core


Just a couple of minor things:

+@cindex @code{fallthrough} statement attribute
+The @code{fallthrough} attribute with a null statement serves as a
+fallthrough statement.  It hints to the compiler that a statement
+that falls through to another case label, or user-defined label
+in a switch statement is intentional and thus the
+@option{-Wimplicit-fallthrough} warning must not trigger.  The
+fallthrough attribute might appear at most once in each attribute
+list, and might not be mixed with other attributes.

"Might appear" means that it may or may not appear (we don't know),
but the intent is to say that it's allowed to appear at most once.
Such a constraint is more correctly phrased in terms of either may
or or must, for example:

  The fallthrough attribute may appear at most once.

or

 The fallthrough attribute must not appear more than once.

Same for "might not be mixed with."

In (very light) testing I noticed that in the following, the switch
in h() is diagnosed but the one in g() is not.

Martin

  int f (void);

  #define foo() for ( ; ; ) { if (f ()) break; }
  #define bar() do { if (f ()) break; } while (0)

  int g (int i)
  {
    switch (i) {
    case 0: foo ();
    case 1: return 1;
    }
    return 0;
  }

  int h (int i)
  {
    switch (i) {
    case 0: bar ();
    case 1: return 1;
    }
    return 0;
  }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]