public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52427] New: problem with default copy constructor and -O
@ 2012-02-29  7:22 architectbum at hotmail dot com
  2012-02-29 14:50 ` [Bug c++/52427] [C++11] problem with defaulted " redi at gcc dot gnu.org
  2013-05-25 10:58 ` paolo.carlini at oracle dot com
  0 siblings, 2 replies; 3+ messages in thread
From: architectbum at hotmail dot com @ 2012-02-29  7:22 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52427

             Bug #: 52427
           Summary: problem with default copy constructor and -O
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: architectbum@hotmail.com


Created attachment 26777
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26777
program with unexpected output

The attached program prints
> 181
> 181
as expected when compiled with "g++-4.6.2 --std=c++0x -o bin/main src/main.cc"
(or g++-4.5.3)
but
> 121
> 181
with any -O option, and even
> 17
> 181
with 4.5.3 with -O.

Replacing the default copy constructor of foo_iterator with a user-defined
constructor that should do the same thing (as in comment in source) fixes the
problem, as does compiling with -fno-elide-constructors. Also, as the testcase
shows, the problem arises with 
> sum += *fi++;
but not with
> sum += *fi;
> ++fi;
even though the postfix increment is defined in the usual way; therefore, the
problem seems to lie in the temporary produced by operator++(int).

A GDB session suggested that the optimized-away default copy constructor may be
setting k to 0; that is, k=0 when operator*() is called on the temporary at
'*fi++'; this is consistent with the output. (And moving the "dereference"
inside operator++(int) so that it returns ulong does the same thing.)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-05-25 10:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-29  7:22 [Bug c++/52427] New: problem with default copy constructor and -O architectbum at hotmail dot com
2012-02-29 14:50 ` [Bug c++/52427] [C++11] problem with defaulted " redi at gcc dot gnu.org
2013-05-25 10:58 ` paolo.carlini at oracle dot com

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).