Files
nethack/win/Qt
nhmall 0792e5fe9e expand implicit fallthrough detection to non-gcc compilers
gcc has recognized various "magic comments" for white-listing
occurrences of implicit fallthrough in switch statements for
a long time:

    The range and shape of "falls through" comments accepted are
    contingent upon the level of the warning. (The default level is =3.)

    -Wimplicit-fallthrough=0 disables the warning altogether.
    -Wimplicit-fallthrough=1 treats any kind of comment as a "falls through" comment.
    -Wimplicit-fallthrough=2 essentially accepts any comment that contains something
     that matches (case insensitively) "falls?[ \t-]*thr(ough|u)" regular expression.
    -Wimplicit-fallthrough=3 case sensitively matches a wide range of regular
     expressions, listed in the GCC manual. E.g., all of these are accepted:
        /* Falls through. */
        /* fall-thru */
        /* Else falls through. */
        /* FALLTHRU */
        /* ... falls through ... */
       etc.
    -Wimplicit-fallthrough=4 also, case sensitively matches a range of regular
     expressions but is much more strict than level =3.
    -Wimplicit-fallthrough=5 doesn't recognize any comments.

Plenty of other compilers did not recognize the gcc comment convention,
and up until now the compiler warning for detecting unintended
fallthrough had to be suppressed on other compilers. That's because the code
in NetHack has been relying on the gcc approach, and only the gcc approach.

The C23 standard introduces an attribute [[fallthrough]] for the
functionality, when implicit fallthrough warnings have been enabled.

Several popular compilers already support that, or a very similar attribute
style approach, today, even ahead of their C23 support:

       C compiler                       whitelist approach
       ---------------------------   -------------------------------------
       C23 conforming compilers         [[fallthrough]]

       clang versions supporting
       standards prior to
       C23                              __attribute__((__fallthrough__))

       Microsoft Visual Studio
       since VS 2022 17.4.
       The warning C5262 controls
       whether the implict
       fallthrough is detected and
       warned about with
       /std:clatest.                    [[fallthrough]]

This adds support to NetHack for the attribute approach by inserting a
macro FALLTHROUGH to the existing cases that require white-listing, so
other compilers can analyze things too.

The definition of the FALLTHROUGH macro is controlled in include/tradstdc.h.

The gcc comment approach has also been left in place at this time.
2024-11-30 14:16:27 -05:00
..
2019-12-07 17:07:50 +01:00
2019-12-07 17:07:50 +01:00
2021-12-30 11:29:03 -08:00
2019-12-07 17:07:50 +01:00
2020-12-27 17:01:33 -08:00
2019-12-07 17:07:50 +01:00
2021-12-30 11:29:03 -08:00
2019-12-07 17:07:50 +01:00
2023-11-22 16:01:58 -05:00
2022-01-04 12:23:06 -08:00
2022-11-23 13:11:14 -08:00
2023-01-22 12:35:54 -08:00
2019-12-07 17:07:50 +01:00
2021-12-30 11:29:03 -08:00
2021-01-08 13:47:34 -08:00
2021-12-30 11:29:03 -08:00
2019-12-07 17:07:50 +01:00
2024-07-13 16:31:35 -04:00
2022-01-10 13:23:09 -08:00
2022-06-11 13:52:58 -04:00
2023-04-04 14:25:24 -04:00
2022-11-23 13:11:14 -08:00
2019-12-07 17:07:50 +01:00
2024-02-28 20:15:56 -08:00
2024-02-28 11:47:16 -08:00
2024-02-28 11:47:16 -08:00
2022-11-23 13:11:14 -08:00
2022-11-23 13:11:14 -08:00
2021-12-30 11:29:03 -08:00
2020-11-05 14:36:13 -08:00
2024-10-12 15:03:54 -07:00
2019-12-07 17:07:50 +01:00
2024-02-28 20:15:56 -08:00
2024-02-28 20:15:56 -08:00
2021-04-11 14:55:45 -07:00
2024-02-28 20:15:56 -08:00
2024-07-13 16:31:35 -04:00
2024-02-28 20:15:56 -08:00
2024-10-12 15:03:54 -07:00