public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97435] New: Lifetime of temporaries not correctly extending when optiimzation are enabled
@ 2020-10-15  6:44 chris at chrissavoie dot com
  2020-10-15  7:33 ` [Bug c++/97435] " rguenth at gcc dot gnu.org
  2020-10-15  8:51 ` redi at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: chris at chrissavoie dot com @ 2020-10-15  6:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97435

            Bug ID: 97435
           Summary: Lifetime of temporaries not correctly extending when
                    optiimzation are enabled
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chris at chrissavoie dot com
  Target Milestone: ---

Godbolt example: https://godbolt.org/z/fssed1

The following code:
struct A {
    __attribute__((noinline))
    A(int i) : data(i) {}
    A& operator+=(int i) { data += i; return *this; }
    int data;
};

int main() {
    A const& b = A(5) += 5;
    A c(6);
    return b.data + c.data; // 16 expected
}

Will return 16 when compiled without optimizations, 11 when compiled with
optimizations (-O1 or greater) and 6 with noinline disabled and optimizations
on.

Browsing versions on godbolt it looks like the inline version of the bug
appeared between versions 4.9.3 and 5.1. The noinline version appeared between
versions 4.6.4 and 4.7.3.

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

end of thread, other threads:[~2020-10-15  8:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-15  6:44 [Bug c++/97435] New: Lifetime of temporaries not correctly extending when optiimzation are enabled chris at chrissavoie dot com
2020-10-15  7:33 ` [Bug c++/97435] " rguenth at gcc dot gnu.org
2020-10-15  8:51 ` 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).