I am using GCC version 8.3 and have a switch statement:
#include <iostream>
enum class Type : char
{
Value1 = 'A',
Value2,
Value3,
Value4,
};
int main()
{
Type t;
switch(t)
{
case Type::Value1:
case Type::Value2:
case Type::Value3:
std::cout << "hw" << std::endl;
case Type::Value4:
break;
}
}
I want to be forced to use [[fallthrough]] otherwise generate a warning.
I added gcc flags to detect missing enums and implict fallthrough:
g++ -o main.cc -O3 -Wswitch-enum -Wimplicit-fallthrough -std=c++1z
The new flags have been detected because I now get warnings I'm missing enums. I fixed those but I still receive no warnings about implicit fallthrough.
I've put the code here:
https://godbolt.org/z/rj5sTPWz4
Am I missing something? I was expecting to be warned?
UPDATE:
I changed the code to this:
struct Object
{
int a;
};
int main()
{
Type t;
Object o;
switch(t)
{
case Type::Value1:
case Type::Value2:
case Type::Value3:
case Type::Value4:
o.a = 5;
break;
}
}
and it still doesn't generate a warning.