I compile this with GCC 7.2.0:
typedef float Signal_t;
enum class Signal_level : Signal_t {
low = -1.0, neutral = 0.0, high = 1.0
};
the compiler response is:
error: underlying type ‘Signal_t {aka float}’ of ‘Signal_level’ must be an integral type
Is this behavior dictated by the standard (-std=c++17) or is specific to GCC?
I'd expect GCC to recognize Signal_t as an integral type.
According to [dcl.enum]p2:
Here the type-specifier-seq refers to the part after
:.And what are integral types ([basic.types]p7):
So a float is not part of the integral types, and so is not valid to use in an enum as base.