I'm getting a warning ([-Wmaybe-uninitialized]) on some code that I don't think should be throwing a warning. Compiling with cmake using GCC. Basically it's saying that a variable may not be initialized, but I think it's guaranteed to be initialized. Here's an example:
#include<iostream>
enum class ByteOrder
{
little_endian,
big_endian
};
class someClass
{
someClass(ByteOrder order = ByteOrder::little_endian) :
kOrder{order}
{}
void someFunc();
private:
const ByteOrder kOrder;
};
void someClass::someFunc()
{
int i;
switch(kOrder)
{
case ByteOrder::little_endian:
i = 0;
break;
case ByteOrder::big_endian:
i = 1;
break;
}
std::cout << i;
}
According to GCC, i at the line
std::cout << i;
could be uninitialized. But I don't see how that's possible since there are only two options in the switch statement. I tried setting ByteOrder
to nullptr
but that didn't work. Am I missing something here?