public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/92798] -fshort-enums can break iterators of std::map
[not found] <bug-92798-4@http.gcc.gnu.org/bugzilla/>
@ 2023-10-05 17:43 ` josephttilahun at gmail dot com
2023-10-05 17:48 ` pinskia at gcc dot gnu.org
2023-10-07 11:44 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 3+ messages in thread
From: josephttilahun at gmail dot com @ 2023-10-05 17:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92798
Joseph Tilahun <josephttilahun at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |josephttilahun at gmail dot com
--- Comment #4 from Joseph Tilahun <josephttilahun at gmail dot com> ---
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?
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/92798] -fshort-enums can break iterators of std::map
[not found] <bug-92798-4@http.gcc.gnu.org/bugzilla/>
2023-10-05 17:43 ` [Bug libstdc++/92798] -fshort-enums can break iterators of std::map josephttilahun at gmail dot com
@ 2023-10-05 17:48 ` pinskia at gcc dot gnu.org
2023-10-07 11:44 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-05 17:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92798
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug libstdc++/92798] -fshort-enums can break iterators of std::map
[not found] <bug-92798-4@http.gcc.gnu.org/bugzilla/>
2023-10-05 17:43 ` [Bug libstdc++/92798] -fshort-enums can break iterators of std::map josephttilahun at gmail dot com
2023-10-05 17:48 ` pinskia at gcc dot gnu.org
@ 2023-10-07 11:44 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2023-10-07 11:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92798
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
We could add an enumerator that forces sizeof(_Rb_tree_color) == sizeof(int),
which would be valid for C++98.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-10-07 11:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-92798-4@http.gcc.gnu.org/bugzilla/>
2023-10-05 17:43 ` [Bug libstdc++/92798] -fshort-enums can break iterators of std::map josephttilahun at gmail dot com
2023-10-05 17:48 ` pinskia at gcc dot gnu.org
2023-10-07 11:44 ` redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).