Path: csiph.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: bugprone-switch-missing-default-case Date: Thu, 23 Oct 2025 19:13:31 -0700 Organization: None to speak of Lines: 48 Message-ID: <87y0p111ys.fsf@example.invalid> 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> <87frb92op0.fsf@example.invalid> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Fri, 24 Oct 2025 02:13:32 +0000 (UTC) Injection-Info: dont-email.me; posting-host="69089273d8ad8cb61d3f6cd6f642af28"; logging-data="2409985"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7Jko9N2eGIlS7/U6V57bB" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:ytAIqUngZ0w2YC2jtLpt1WU7sXI= sha1:NGraF6MQ6biHWua1pmVvFZF3RCQ= Xref: csiph.com comp.lang.c:394699 Keith Thompson writes: > pozz 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). And now it's been updated: 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 switch statement will do nothing and the program will continue execution without handling the value. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */