Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #394693
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
| Newsgroups | comp.lang.c |
| Subject | Re: bugprone-switch-missing-default-case |
| Date | Thu, 23 Oct 2025 16:17:15 -0700 |
| Organization | None to speak of |
| Lines | 67 |
| Message-ID | <87frb92op0.fsf@example.invalid> (permalink) |
| References | <10da67g$3q59f$1@dont-email.me> <10da8bo$hker$1@dont-email.me> <10dag3d$jkju$1@dont-email.me> <10damv3$ku01$1@dont-email.me> <87frbaohaa.fsf@example.invalid> <10dcj1l$3t7o6$1@dont-email.me> |
| MIME-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Date | Thu, 23 Oct 2025 23:17:17 +0000 (UTC) |
| Injection-Info | dont-email.me; posting-host="e54c71aeed92b5fcba070e440314529c"; logging-data="2344065"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Sb7BPSgYByf96X2YqN8pL" |
| User-Agent | Gnus/5.13 (Gnus v5.13) |
| Cancel-Lock | sha1:8UVff9uoKWYBszrfJGx0Dv1hFjM= sha1:6nWQPC02s1/JNzMJZVVF5nMyLxA= |
| Xref | csiph.com comp.lang.c:394693 |
Show key headers only | View raw
pozz <pozzugno@gmail.com> writes:
> Il 22/10/2025 21:41, Keith Thompson ha scritto:
[...]
>> That document is poorly written. The phrase "without any defined
>> behavior" strongly implies that the behavior is undefined, which is
>> simply wrong.
>> It says:
>> When a switch statement lacks a default case, if a value is
>> encountered that does not match any of the specified cases, the
>> program will continue execution without any defined behavior or
>> handling.
>> It would be more accurate to say:
>> When a switch statement lacks a default case, if a value is
>> encountered that does not match any of the specified cases, the
>> switch statement will do nothing and the program will continue
>> execution without handling the value.
>> A warning might be warranted, but the behavior is well defined.
>
> It is exactly what i wanted to read. Thanks for the explanation.
>
>
>> Note that the documentation is for the add-on tool clang-tidy, not for
>> the clang compiler.
>
> Sure
>
>
>> I've submitted a bug report :
>> https://github.com/llvm/llvm-project/issues/164699
My fix for this has been accepted into the llvm-project git repo.
The web page
https://clang.llvm.org/extra/clang-tidy/checks/bugprone/switch-missing-default-case.html
has not yet been updated (not surprisingly).
commit b474be668091301d4a214da922f0cb98d416dc6b
Author: Keith Thompson <Keith.S.Thompson@gmail.com>
Date: 2025-10-23 02:41:12 -0700
[clang-tidy][NFC] Clarify switch-missing-default-case doc (#164699) (#164709)
Falling through a defaultless switch statement has well defined
behavior. Fixes https://github.com/llvm/llvm-project/issues/164699.
Credit for noticing this problem goes to user "pozz" on comp.lang.c,
Message-ID: <10da67g$3q59f$1@dont-email.me>
diff --git clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
index 648c2c208a4e..3ce862ff8afc 100644
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/switch-missing-default-case.rst
@@ -9,8 +9,8 @@ on covering cases with non-enums where the compiler may not issue warnings.
Switch statements without a default case can lead to unexpected
behavior and incomplete handling of all possible cases. When a switch statement
lacks a default case, if a value is encountered that does not match any of the
-specified cases, the program will continue execution without any defined
-behavior or handling.
+specified cases, the switch statement will do nothing and the program will
+continue execution without handling the value.
This check helps identify switch statements that are missing a default case,
allowing developers to ensure that all possible cases are handled properly.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
bugprone-switch-missing-default-case pozz <pozzugno@gmail.com> - 2025-10-22 10:56 +0200
Re: bugprone-switch-missing-default-case Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-22 11:32 +0200
Re: bugprone-switch-missing-default-case Richard Harnden <richard.nospam@gmail.invalid> - 2025-10-22 12:44 +0100
Re: bugprone-switch-missing-default-case Thiago Adams <thiago.adams@gmail.com> - 2025-10-22 10:05 -0300
Re: bugprone-switch-missing-default-case Kaz Kylheku <643-408-1753@kylheku.com> - 2025-10-22 18:22 +0000
Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-23 09:12 +0200
Re: bugprone-switch-missing-default-case Thiago Adams <thiago.adams@gmail.com> - 2025-10-23 08:03 -0300
Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-23 17:06 +0200
Re: bugprone-switch-missing-default-case Thiago Adams <thiago.adams@gmail.com> - 2025-10-23 13:15 -0300
Re: bugprone-switch-missing-default-case bart <bc@freeuk.com> - 2025-10-23 17:46 +0100
Re: bugprone-switch-missing-default-case Thiago Adams <thiago.adams@gmail.com> - 2025-10-23 14:12 -0300
Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-23 22:40 +0200
Re: bugprone-switch-missing-default-case scott@slp53.sl.home (Scott Lurndal) - 2025-10-23 20:51 +0000
Re: bugprone-switch-missing-default-case Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-10-23 16:21 -0700
Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-24 08:59 +0200
Re: bugprone-switch-missing-default-case scott@slp53.sl.home (Scott Lurndal) - 2025-10-24 15:51 +0000
Re: bugprone-switch-missing-default-case tTh <tth@none.invalid> - 2025-10-23 23:57 +0200
Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-24 09:22 +0200
Re: bugprone-switch-missing-default-case antispam@fricas.org (Waldek Hebisch) - 2025-10-23 23:23 +0000
Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-24 09:53 +0200
Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-22 15:41 +0200
Re: bugprone-switch-missing-default-case Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-22 16:05 +0200
Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-22 17:23 +0200
Re: bugprone-switch-missing-default-case Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-23 04:54 +0200
Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-23 09:30 +0200
Re: bugprone-switch-missing-default-case antispam@fricas.org (Waldek Hebisch) - 2025-10-23 22:40 +0000
Re: bugprone-switch-missing-default-case Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-10-22 12:41 -0700
Re: bugprone-switch-missing-default-case pozz <pozzugno@gmail.com> - 2025-10-23 08:47 +0200
Re: bugprone-switch-missing-default-case Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-10-23 16:17 -0700
Re: bugprone-switch-missing-default-case Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-10-23 19:13 -0700
Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-23 10:44 +0200
Re: bugprone-switch-missing-default-case Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-22 15:56 +0200
Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-22 17:25 +0200
Re: bugprone-switch-missing-default-case Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-23 04:39 +0200
Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-23 09:08 +0200
Re: bugprone-switch-missing-default-case Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-10-23 16:31 -0700
Re: bugprone-switch-missing-default-case David Brown <david.brown@hesbynett.no> - 2025-10-24 10:09 +0200
Re: bugprone-switch-missing-default-case Kaz Kylheku <643-408-1753@kylheku.com> - 2025-10-22 18:13 +0000
csiph-web