public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/61213] New: std::forward_as_tuple and std::tuple<T&&> and any rvalue loose data
@ 2014-05-17 12:59 tower120 at gmail dot com
  2014-05-17 14:01 ` [Bug c++/61213] [4.7/4.8/4.9/4.10 Regression] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: tower120 at gmail dot com @ 2014-05-17 12:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 61213
           Summary: std::forward_as_tuple and std::tuple<T&&> and any
                    rvalue loose data
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tower120 at gmail dot com

std::forward_as_tuple elements loose data on -O2.
Works fine with -O0


Consider the following code:
http://coliru.stacked-crooked.com/a/67499e052283bd5a

#include <iostream>
#include <tuple>

class Widget {
public:
  Widget(int h) : h(h){}
  int h;
};

template<typename T>
struct RvalueTest{
    RvalueTest(T&& value) : value( std::forward<T>(value) ){}
    T&& value;
};

int main() {
    auto t = std::forward_as_tuple(Widget(12));
    //auto t = std::tuple<Widget&&>(Widget(12));  // this not work also
    std::cout << std::get<0>(t).h;                // <-- some random value here

    /// This one not work, either:    
    /*RvalueTest<Widget> r(Widget(12));
    std::cout << r.value.h;*/
}


Code from above works fine with clang compiler.
I suspect that rvalue object life time is wrong in -O2 mode.


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

* [Bug c++/61213] [4.7/4.8/4.9/4.10 Regression] std::forward_as_tuple and std::tuple<T&&> and any rvalue loose data
  2014-05-17 12:59 [Bug c++/61213] New: std::forward_as_tuple and std::tuple<T&&> and any rvalue loose data tower120 at gmail dot com
@ 2014-05-17 14:01 ` redi at gcc dot gnu.org
  2014-05-17 14:20 ` tower120 at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2014-05-17 14:01 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-05-17
      Known to work|                            |4.6.4
            Summary|std::forward_as_tuple and   |[4.7/4.8/4.9/4.10
                   |std::tuple<T&&> and any     |Regression]
                   |rvalue loose data           |std::forward_as_tuple and
                   |                            |std::tuple<T&&> and any
                   |                            |rvalue loose data
     Ever confirmed|0                           |1
      Known to fail|                            |4.10.0, 4.7.3, 4.8.2, 4.9.0

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
4.6 gave the right answer

Using -fno-indirect-inlining gives the correct result

Also reproducable with -O1 -findirect-inlining -finline-small-functions


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

* [Bug c++/61213] [4.7/4.8/4.9/4.10 Regression] std::forward_as_tuple and std::tuple<T&&> and any rvalue loose data
  2014-05-17 12:59 [Bug c++/61213] New: std::forward_as_tuple and std::tuple<T&&> and any rvalue loose data tower120 at gmail dot com
  2014-05-17 14:01 ` [Bug c++/61213] [4.7/4.8/4.9/4.10 Regression] " redi at gcc dot gnu.org
@ 2014-05-17 14:20 ` tower120 at gmail dot com
  2014-05-17 14:30 ` glisse at gcc dot gnu.org
  2014-05-17 14:54 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: tower120 at gmail dot com @ 2014-05-17 14:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from tower120 <tower120 at gmail dot com> ---
(In reply to Jonathan Wakely from comment #1)
> Using -fno-indirect-inlining gives the correct result

I not see this with
-std=c++11 -O2 -fno-indirect-inlining -Wall -pedantic -pthread

http://coliru.stacked-crooked.com/a/e7c9408daef01448


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

* [Bug c++/61213] [4.7/4.8/4.9/4.10 Regression] std::forward_as_tuple and std::tuple<T&&> and any rvalue loose data
  2014-05-17 12:59 [Bug c++/61213] New: std::forward_as_tuple and std::tuple<T&&> and any rvalue loose data tower120 at gmail dot com
  2014-05-17 14:01 ` [Bug c++/61213] [4.7/4.8/4.9/4.10 Regression] " redi at gcc dot gnu.org
  2014-05-17 14:20 ` tower120 at gmail dot com
@ 2014-05-17 14:30 ` glisse at gcc dot gnu.org
  2014-05-17 14:54 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: glisse at gcc dot gnu.org @ 2014-05-17 14:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> ---
Are you sure the code is valid? It doesn't seem so to me.

gcc's optimizers have become good enough to recycle the space from dead
temporaries.


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

* [Bug c++/61213] [4.7/4.8/4.9/4.10 Regression] std::forward_as_tuple and std::tuple<T&&> and any rvalue loose data
  2014-05-17 12:59 [Bug c++/61213] New: std::forward_as_tuple and std::tuple<T&&> and any rvalue loose data tower120 at gmail dot com
                   ` (2 preceding siblings ...)
  2014-05-17 14:30 ` glisse at gcc dot gnu.org
@ 2014-05-17 14:54 ` redi at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2014-05-17 14:54 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Marc Glisse from comment #3)
> Are you sure the code is valid? It doesn't seem so to me.

Good point, the Widget temporary goes out of scope at the end of the expression
and the tuple holds a dangling reference.


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

end of thread, other threads:[~2014-05-17 14:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-17 12:59 [Bug c++/61213] New: std::forward_as_tuple and std::tuple<T&&> and any rvalue loose data tower120 at gmail dot com
2014-05-17 14:01 ` [Bug c++/61213] [4.7/4.8/4.9/4.10 Regression] " redi at gcc dot gnu.org
2014-05-17 14:20 ` tower120 at gmail dot com
2014-05-17 14:30 ` glisse at gcc dot gnu.org
2014-05-17 14:54 ` 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).