[Bug libstdc++/92798] -fshort-enums can break iterators of std::map
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92798 --- Comment #6 from Jonathan Wakely --- We could add an enumerator that forces sizeof(_Rb_tree_color) == sizeof(int), which would be valid for C++98.
[Bug libstdc++/92798] -fshort-enums can break iterators of std::map
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92798 --- Comment #5 from Andrew Pinski --- (In reply to Joseph Tilahun from comment #4) > Is there a reason why the _Rb_tree_color > enum does not have an explicit underlying type? Yes because it has to work with C++98 while enums with underlying types was only added for C++11. Again -fshort-enums changes the ABI so you can't use that option unless you compile everything with it.
[Bug libstdc++/92798] -fshort-enums can break iterators of std::map
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92798 Joseph Tilahun changed: What|Removed |Added CC||josephttilahun at gmail dot com --- Comment #4 from Joseph Tilahun --- I encountered this same bug when using -fshort-enums with std::map iterators. The fact that -fshort-enums breaks std::map iterators implies that there's an enum somewhere without an explicit underlying type. In /usr/include/c++/9/bits/stl_tree.h, there's an enum that enumerates the possible colors of a node of a red-black tree: enum _Rb_tree_color { _S_red = false, _S_black = true }; struct _Rb_tree_node_base { typedef _Rb_tree_node_base* _Base_ptr; typedef const _Rb_tree_node_base* _Const_Base_ptr; _Rb_tree_color _M_color; _Base_ptr _M_parent; _Base_ptr _M_left; _Base_ptr _M_right; // Other code that's not relevant } The _Rb_tree_color enum does not have an explicit underlying type. I tried modifying this to: enum _Rb_tree_color : int { _S_red = false, _S_black = true }; struct _Rb_tree_node_base { typedef _Rb_tree_node_base* _Base_ptr; typedef const _Rb_tree_node_base* _Const_Base_ptr; _Rb_tree_color _M_color; _Base_ptr _M_parent; _Base_ptr _M_left; _Base_ptr _M_right; // Other code that's not relevant } and -fshort-enums does not break this. I also tried modifying this to: enum _Rb_tree_color { _S_red = false, _S_black = true }; struct _Rb_tree_node_base { typedef _Rb_tree_node_base* _Base_ptr; typedef const _Rb_tree_node_base* _Const_Base_ptr; int _M_color; _Base_ptr _M_parent; _Base_ptr _M_left; _Base_ptr _M_right; // Other code that's not relevant } and -fshort-enums does not break this. It seems to me that the _Rb_tree_color enum is the real problem. -fshort-enums simply exposes the fact that the _Rb_tree_color enum does not have an explicit underlying type. Is there a reason why the _Rb_tree_color enum does not have an explicit underlying type?
[Bug libstdc++/92798] -fshort-enums can break iterators of std::map
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92798 Jonathan Wakely changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #3 from Jonathan Wakely --- (In reply to Christian N from comment #2) > It didn't occur to me that basically everything needs recompilation with > -fshort-enums, but it makes perfect sense. Read the fabulous manual: Warning: the -fshort-enums switch causes GCC to generate code that is not binary compatible with code generated without that switch. Use it to conform to a non-default application binary interface. > I suppose this report can be closed as invalid then!? OK, done.
[Bug libstdc++/92798] -fshort-enums can break iterators of std::map
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92798 --- Comment #2 from Christian N --- To be honest, I'm not sure when and why it came to be. The build instructions are partially from an old project and weren't cleaned properly. The immediate code base actually only uses scoped enums. The problem just came up and upon investigating, removing the flag fixed it. It didn't occur to me that basically everything needs recompilation with -fshort-enums, but it makes perfect sense. I suppose this report can be closed as invalid then!? Thanks!
[Bug libstdc++/92798] -fshort-enums can break iterators of std::map
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92798 --- Comment #1 from Jonathan Wakely --- -fshort-enums is an ABI-changing option, which means you should recompile the entire toolchain including the standard libraries. Why are you using it anyway? In C++ you can specify a fixed underlying type, so you can control the exact size of each enumeration type.