This is pretty much the same question as Does adding enumerators into enum break ABI?, but with enum class
introduced by C++11.
For what I understand by this page I can simply have a stable ABI by defining an underlying type for my enumerative:
enum class Foo : uint32_t
{
x, y, z
}
I would say this works fine, as for instance something like
enum class Foo : uint8_t { x = 257 }
Will not compile. This implies that the compiler is no longer silently changing the size of my enumerative, thus I don't end up in breaking binary compatibility.
Am I correct?
I believe the accepted answer to the referenced question answers most of the issues with respect to ABI compatibility. I could repeat it here but I don't see much value there.
To address you specific question about C++11 scoped enumerations your example:
enum class Foo : uint8_t { x = 257 }
is ill-formed since it requires a narrowing conversion, the implementation is required to provide a diagnostic but it may compile if the implementation only makes it warning for example. As you ask, the compiler won't silently change the size of underlying type.
We can see this from the draft C++ standard dcl.enump5:
Each enumeration defines a type that is different from all other types. Each enumeration also has an underlying type. The underlying type can be explicitly specified using an enum-base. For a scoped enumeration type, the underlying type is int if it is not explicitly specified. In both of these cases, the underlying type is said to be fixed. Following the closing brace of an enum-specifier, each enumerator has the type of its enumeration. If the underlying type is fixed, the type of each enumerator prior to the closing brace is the underlying type and the constant-expression in the enumerator-definition shall be a converted constant expression of the underlying type. If the underlying type is not fixed, the type of each enumerator prior to the closing brace is determined as follows: ...
and converted constant expression forbid narrowing conversion, from expr.constp5:
A converted constant expression of type T is an expression, implicitly converted to type T, where the converted expression is a constant expression and the implicit conversion sequence contains only
...
- integral conversions other than narrowing conversions,
...