Without this change, GCC 7 raises the warning below:
control reaches end of non-void function
Differential D46304
[MC] Add llvm_unreachable to toString to fix compile time warning. fhahn on May 1 2018, 1:19 AM. Authored by
Details Without this change, GCC 7 raises the warning below: control reaches end of non-void function
Diff Detail
Event TimelineComment Actions I just saw that Gabor fixed it at revision 331251 adding a 'default' case. Comment Actions Ah thanks for pointing me to that :) @GBuella I think one minor drawback of adding a default cast is that we won't get compiler warning for missing cases, but then when WasmSymbolType is not an enum class, you probably won't get them anyways. Comment Actions Your approach is better. Adding a default case is not a good workaround because it introduces another warning: /Users/buildslave/as-bldslv9/lld-x86_64-darwin13/llvm.src/lib/MC/WasmObjectWriter.cpp:50:3: error: default label in switch which covers all enumeration values [-Werror,-Wcovered-switch-default] default: ^ Can you push your patch to fix the buildbots? Cheers, Comment Actions Thanks for the fix! So the wording of this warning is definitely wrong (unless there would be cases for 2^32 enumeration values): llvm/lib/MC/WasmObjectWriter.cpp:50:3: error: default label in switch which covers all enumeration values [-Werror,-Wcovered-switch-default] default: ^ Comment Actions Hey there - I implemented this diagnostic many a year ago. Yeah, technically maybe "covers all enumerators" might be more accurate phrasing? Comment Actions
I'm not sure. I would rather enable this warning only on enums without fixed type, i.e. "enum XX {}", and not use this warning with "enum XX : unsigned {}". Or these could be two distinct warnings. E.g. I guess this WasmSymbolType is marked as unsigned, because it might be read from a binary file, in which case that input might contain invalid values, by which I values not matching the enumerated enumeration values. This is probably already validated before this toString function is called, but still. Comment Actions The wording says the values of the enumeration are the values of the underlying type. I think perhaps that wording is a little wrong. Perhaps the final the should be removed? Surly what it trying to say is that is that the valid enum values are themselves values of the underlying type, not that *all* possible value of the underlying type are also valid enum values. Comment Actions
@sbc100, just read after that sentence: So, for one without a fixed type, the way I would interpret it, the following type has 7 valid values (0, 1, 2, 3, 4, 5, 6, 7): enum x { a = 2 b = 6 }; A bit later on it is explicitly stated, that: And I believe in the case of those with fixed types, the range of the "values of the enumeration" is just extended to *all* possible values of that underlying type -- well, that would make sense to me. BTW, yes, "covers all enumerators" might be more accurate phrasing -- that surely is OK for all kinds of C++ enums, and for C enums. |