Article View: linux.debian.bugs.dist
Article #2985Bug#1152860: g++ switch/case epic bug
From: Colin Watson
Date: Mon, 02 Nov 2026 14:10
Date: Mon, 02 Nov 2026 14:10
42 lines
3059 bytes
3059 bytes
On Mon, Nov 02, 2026 at 03:59:12PM +0300, Ivan Beliew wrote:
> Package: g++ Version: 4:14.2.0-1
> The following code compilation should never success:
>
> #include <iostream>
> enum class key {A, B};
> void test(key k)
> {
> switch (k)
> {
> case key::A:
> std::cerr << "A\n";
> break;
> deafult: // HERE!!!
> std::cerr << "DFL\n";
> break;
> }
> }
Although I agree you've misspelled "default", this is nevertheless legal
because it looks just like a label, and you're allowed to have a label
named "deafult".
-Wall diagnoses this clearly, so you have the tools necessary to make
this class of problems into an error if you want (e.g. -Werror=switch or
-Werror=unused-label):
$ g++ -Wall -pedantic -o run run.cpp
run.cpp: In function ‘void test(key)’:
run.cpp:5:12: warning: enumeration value ‘B’ not handled in switch [-Wswitch]
5 | switch (k)
| ^
run.cpp:10:9: warning: label ‘deafult’ defined but not used [-Wunused-label]
10 | deafult: // HERE!!!
| ^~~~~~~
I suggest that this bug should be closed.
Thanks,
--
Colin Watson (he/him) [cjwatson@debian.org]
Technical Details
Message-ID:
<NV0Tv-9pYy-1@gated-at.bofh.it>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomodReferences:
<NV0Tv-9pYy-3@gated-at.bofh.it> <NV0Tv-9pYy-3@gated-at.bofh.it>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod From: Colin Watson <cjwatson@debian.org> Newsgroups: linux.debian.bugs.dist Subject: Bug#1152860: g++ switch/case epic bug Date: Mon, 02 Nov 2026 15:10:01 +0100 Message-ID: <NV0Tv-9pYy-1@gated-at.bofh.it> References: <NV0Tv-9pYy-3@gated-at.bofh.it> <NV0Tv-9pYy-3@gated-at.bofh.it> X-Mailbox-Line: From debian-bugs-dist-request@lists.debian.org Mon Nov 2 14:01:07 2026 Old-Return-Path: <debbugs@buxtehude.debian.org> X-Spam-Flag: NO X-Spam-Score: -1.7 Reply-To: Colin Watson <cjwatson@debian.org>, 1152860@bugs.debian.org Resent-To: debian-bugs-dist@lists.debian.org Resent-Cc: debian-gcc@lists.debian.org X-Debian-Pr-Message: followup 1152860 X-Debian-Pr-Package: g++ X-Debian-Pr-Source: gcc-defaults, gcc-defaults-mipsen MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Debian-User: cjwatson X-Debian-Message: from BTS X-Mailing-List: <debian-bugs-dist@lists.debian.org> archive/latest/2000247 List-ID: <debian-bugs-dist.lists.debian.org> List-URL: <https://lists.debian.org/debian-bugs-dist/> Approved: robomod@news.nic.it Lines: 42 Organization: linux.* mail to news gateway Sender: robomod@news.nic.it X-Original-Date: Mon, 2 Nov 2026 13:59:01 +0000 X-Original-Message-ID: <auiXJamzRnPFUGEy@riva.ucam.org> X-Original-References: <1793624352.685539411@5.f.mail-release.pc.mrucl.ru> <1793624352.685539411@5.f.mail-release.pc.mrucl.ru>