This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ Patch / RFC] PR 51242


Hi,

this PR is about the rejection (in C++11 mode of course) of:

enum class MyEnum { A = 1 };

struct MyClass
{
  MyEnum Field1 : 3;
};


whereas the corresponding unscoped enum case already works. As noticed by Jon, it seems that the below straightforward patchlet is enough to solve the problem but then we have a warning issue:


51242.C:5:19: warning: ‘MyClass::Field1’ is too small to hold all values of ‘enum class MyEnum’ [enabled by default]

which is easily explained: the underlying type is fixed (to an implicit int type), thus in finish_enum_value_list, fixed_underlying_type_p is true and the code "restricting" the ENUM_UNDERLYING_TYPE for diagnostic purposes doesn't run. In other terms, we warn for the same reason we for example -Wnarrowing warn (before erroring out) for:

enum class Code {
  SUCCESS = 0
};

Code a;

short r[] = {a};


That seems intended, but especially annoying in the bitfield case. An idea could be giving a name to the "too small to hold all values" warning and making possible disabling it. What do you suggest?


Thanks!
Paolo.

Attachment: p
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]