🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.debian.bugs.dist
1 messages
1 total messages Started by Colin Watson Mon, 02 Nov 2026 14:10
Bug#1152860: g++ switch/case epic bug
#2985
Author: Colin Watson
Date: Mon, 02 Nov 2026 14:10
42 lines
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]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads