Sujet : Re: enums and switch vs function calls
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.cDate : 05. Apr 2025, 16:58:37
Autres entêtes
Organisation : Stefan Ram
Message-ID : <C++-20250405165820@ram.dialup.fu-berlin.de>
References : 1 2
ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
int hex = colour_to_hex(10);
However,
|colour_to_hex((enum colour)10)
compiles as C under the above option without warnings,
while compiling it as C++ one gets:
|warning: The value '10' provided to the cast expression is not in the valid range of values for 'colour' [clang-analyzer-optin.core.EnumCastOutOfRange]
|warning: the result of the conversion is unspecified because '10' is outside the range of type 'colour' [-Wconversion]
.