public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/50776] New: unused object optimized out, despite having constructor
@ 2011-10-18 14:10 nyh at math dot technion.ac.il
2011-10-18 14:19 ` [Bug c++/50776] " redi at gcc dot gnu.org
2011-10-18 15:47 ` nyh at math dot technion.ac.il
0 siblings, 2 replies; 3+ messages in thread
From: nyh at math dot technion.ac.il @ 2011-10-18 14:10 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50776
Bug #: 50776
Summary: unused object optimized out, despite having
constructor
Classification: Unclassified
Product: gcc
Version: 4.6.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: nyh@math.technion.ac.il
Consider the following simple program:
#include <cstdio>
class Ident {
public:
Ident(const char *ident){
// This constructor prints a message!
printf("yo\n");
}
};
static Ident id("$Id: hello $");
main(){
printf("hello\n");
}
When you compile it with g++ without additional parameters, its output rightly
looks like:
yo
hello
I.e., the object "id" gets instantiated, and its constructor prints the message
"yo".
However, if you compile it with optimization enabled - g++ -O2 - the output is
DIFFERENT: the "id" object is optimized out (because it is static, but nobody
uses it in this source file), and therefore its constructor no longer runs.
I think it is a bug for optimization to change the behavior (not just the
performance) of a program. I think that if an object has a non-trivial
constructor with any side effects beside setting class fields, then we cannot
optimize its construction out because this would change the program behavior.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/50776] unused object optimized out, despite having constructor
2011-10-18 14:10 [Bug c++/50776] New: unused object optimized out, despite having constructor nyh at math dot technion.ac.il
@ 2011-10-18 14:19 ` redi at gcc dot gnu.org
2011-10-18 15:47 ` nyh at math dot technion.ac.il
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2011-10-18 14:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50776
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-10-18 14:18:49 UTC ---
I can't reproduce this with any version.
What platform are you using? (You failed to provide that, as requested by the
http://gcc.gnu.org/bugs/ page)
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/50776] unused object optimized out, despite having constructor
2011-10-18 14:10 [Bug c++/50776] New: unused object optimized out, despite having constructor nyh at math dot technion.ac.il
2011-10-18 14:19 ` [Bug c++/50776] " redi at gcc dot gnu.org
@ 2011-10-18 15:47 ` nyh at math dot technion.ac.il
1 sibling, 0 replies; 3+ messages in thread
From: nyh at math dot technion.ac.il @ 2011-10-18 15:47 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50776
Nadav Har'El <nyh at math dot technion.ac.il> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |WORKSFORME
--- Comment #2 from Nadav Har'El <nyh at math dot technion.ac.il> 2011-10-18 15:46:37 UTC ---
I'm really sorry, I don't know what happened - now I don't see this bug myself!
I must have done something wrong earlier (!?). Closing, and If I ever can
replicate this again, I'll reopen. Sorry :(
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-10-18 15:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-18 14:10 [Bug c++/50776] New: unused object optimized out, despite having constructor nyh at math dot technion.ac.il
2011-10-18 14:19 ` [Bug c++/50776] " redi at gcc dot gnu.org
2011-10-18 15:47 ` nyh at math dot technion.ac.il
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).