public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/63388] New: cout of enum class value - segmentation fault
@ 2014-09-27 9:09 kuq03132 at qoika dot com
2014-09-27 9:21 ` [Bug c++/63388] " kuq03132 at qoika dot com
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: kuq03132 at qoika dot com @ 2014-09-27 9:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63388
Bug ID: 63388
Summary: cout of enum class value - segmentation fault
Product: gcc
Version: 4.9.1
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: kuq03132 at qoika dot com
See example:
//==go.cpp============================================
#include <iostream>
enum class Month {jan=1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov,
dec};
std::ostream& operator<<(std::ostream& os, Month m)
{
return os << m; // BUG - SEGMENTATION FAULT
}
int main()
{
Month m = Month::may;
std::cout << m << '\n';
return 0;
}
//====================================================
Compiled and run with:
c++ -std=c++11 -o go go.cpp
./go
Segmentation fault
DON'T WE WANT a COMPILER ERROR INSTEAD?
(Segfaulting with something so "simple" is very dangerous!)
(Problem also if -std=c++14)
To get the code to work correctly, we can convert the Month m to int:
int(m)
std::ostream& operator<<(std::ostream& os, Month m)
{
return os << int(m); // CONVERT TO INT - ok
}
Thanks.
A.
PS: Thanks for the gnu c++ compiler. I know I say "simple" above. But I'm not
fooled. A c++ compiler is a complex monster.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/63388] cout of enum class value - segmentation fault
2014-09-27 9:09 [Bug c++/63388] New: cout of enum class value - segmentation fault kuq03132 at qoika dot com
@ 2014-09-27 9:21 ` kuq03132 at qoika dot com
2014-09-27 10:46 ` schwab@linux-m68k.org
2014-09-27 11:18 ` glisse at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: kuq03132 at qoika dot com @ 2014-09-27 9:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63388
--- Comment #1 from kuq03132 at qoika dot com ---
(problem might be in libstdc++)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/63388] cout of enum class value - segmentation fault
2014-09-27 9:09 [Bug c++/63388] New: cout of enum class value - segmentation fault kuq03132 at qoika dot com
2014-09-27 9:21 ` [Bug c++/63388] " kuq03132 at qoika dot com
@ 2014-09-27 10:46 ` schwab@linux-m68k.org
2014-09-27 11:18 ` glisse at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: schwab@linux-m68k.org @ 2014-09-27 10:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63388
Andreas Schwab <schwab@linux-m68k.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Andreas Schwab <schwab@linux-m68k.org> ---
Endless recursion, os << m is calling operator<<(std::ostream&,Month).
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/63388] cout of enum class value - segmentation fault
2014-09-27 9:09 [Bug c++/63388] New: cout of enum class value - segmentation fault kuq03132 at qoika dot com
2014-09-27 9:21 ` [Bug c++/63388] " kuq03132 at qoika dot com
2014-09-27 10:46 ` schwab@linux-m68k.org
@ 2014-09-27 11:18 ` glisse at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: glisse at gcc dot gnu.org @ 2014-09-27 11:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63388
Marc Glisse <glisse at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Severity|major |normal
--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> ---
I guess it would be possible to have an optional warning, late in the
optimization process, when we see an empty infinite loop:
<bb 3>:
goto <bb 3>;
I don't know how many false positives we would get from that, but the
limitation to an empty block might make them rare enough.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-09-27 11:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-27 9:09 [Bug c++/63388] New: cout of enum class value - segmentation fault kuq03132 at qoika dot com
2014-09-27 9:21 ` [Bug c++/63388] " kuq03132 at qoika dot com
2014-09-27 10:46 ` schwab@linux-m68k.org
2014-09-27 11:18 ` glisse 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).