This is the mail archive of the gcc-bugs@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]

[Bug c++/30277] bit-field: wrong overload resolution


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30277

--- Comment #4 from Tom Honermann <tom at honermann dot net> ---
We recently got bit by this.  It is still an issue in latest gcc trunk:

$ cat t.cpp
enum E : int {
     e1 = 1
};
constexpr E operator-(E, E) {
     return (E)99;
}
typedef struct {
     E e;
     E ebf : 16;
} S;
constexpr S s = { e1, e1 };
static_assert(99 == (int)(s.e-s.e),"Overload resolution failed for
non-bit-field");
static_assert(99 == (int)(s.ebf-s.ebf),"Overload resolution failed for
bit-field");

$ g++ --version
g++ (GCC) 7.0.0 20160721 (experimental)
...

$ g++ -c -std=c++11 t.cpp
t.cpp:9:14: warning: â<anonymous struct>::ebfâ is too small to hold all values
of âenum Eâ
      E ebf : 16;
              ^~
t.cpp:13:1: error: static assertion failed: Overload resolution failed for
bit-field
 static_assert(99 == (int)(s.ebf-s.ebf),"Overload resolution failed for
bit-field");
 ^~~~~~~~~~~~~

(I would love to be able to disable that warning as well: bug 51242)

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