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) [[email protected]]