public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/36461]  New: [C++-0X] Exception throws don't use rvalue reference constructors
@ 2008-06-07 20:19 s_gccbugzilla at nedprod dot com
  2008-06-08 17:08 ` [Bug c++/36461] [c++0x] " s_gccbugzilla at nedprod dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: s_gccbugzilla at nedprod dot com @ 2008-06-07 20:19 UTC (permalink / raw)
  To: gcc-bugs

I will firstly admit that I don't know if exception throws /should/ use rvalue
reference constructors - the proposed working at
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2118.html doesn't
mention it, but one certainly would have thought it would.

In my project I have a destructively copied exception class. Currently, the
standard copy constructor simply moves a pointer to an internal state object
which contains a large amount of debug data eg; stack backtraces. Without this
the debug build can be very slow and stack usage dangerous (there is a bug in
MSVC where copy construction of an exception during a throw doesn't release
previous copies which causes quick exhaustion of the stack).

I have tried to add an rvalue reference constructor under the idea that with
-std=c++0x it would implement move semantics more legally than at current.
Unfortunately, g++ really wants to use the copy constructor for a thrown
exception and won't accept a rvalue copy constructor.

Is this intentional?


-- 
           Summary: [C++-0X] Exception throws don't use rvalue reference
                    constructors
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: s_gccbugzilla at nedprod dot com


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


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

* [Bug c++/36461] [c++0x] Exception throws don't use rvalue reference constructors
  2008-06-07 20:19 [Bug c++/36461] New: [C++-0X] Exception throws don't use rvalue reference constructors s_gccbugzilla at nedprod dot com
@ 2008-06-08 17:08 ` s_gccbugzilla at nedprod dot com
  2008-06-08 17:19 ` s_gccbugzilla at nedprod dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: s_gccbugzilla at nedprod dot com @ 2008-06-08 17:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from s_gccbugzilla at nedprod dot com  2008-06-08 17:07 -------
Created an attachment (id=15732)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15732&action=view)
Test Case


-- 


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


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

* [Bug c++/36461] [c++0x] Exception throws don't use rvalue reference constructors
  2008-06-07 20:19 [Bug c++/36461] New: [C++-0X] Exception throws don't use rvalue reference constructors s_gccbugzilla at nedprod dot com
  2008-06-08 17:08 ` [Bug c++/36461] [c++0x] " s_gccbugzilla at nedprod dot com
@ 2008-06-08 17:19 ` s_gccbugzilla at nedprod dot com
  2008-06-08 17:20 ` s_gccbugzilla at nedprod dot com
  2008-09-24 20:21 ` dgregor at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: s_gccbugzilla at nedprod dot com @ 2008-06-08 17:19 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2167 bytes --]



------- Comment #2 from s_gccbugzilla at nedprod dot com  2008-06-08 17:19 -------
This problem actually seems to be one of subclassing: child class rvalue
constructors invoke base class lvalue constructors!!!

I have attached an example. As is, it compiles and works. If however you throw
a Thing2 instead of Thing, you get:

ned@kate:~/Tornado/Tn/TClient/TnFOX$ g++ -o TestCPP0x -std=c++0x TestCPP0x.cpp
TestCPP0x.cpp: In copy constructor ‘Thing2::Thing2(const Thing2&)’:
TestCPP0x.cpp:9: error: ‘Thing::Thing(const Thing&)’ is private
TestCPP0x.cpp:12: error: within this context
TestCPP0x.cpp: In function ‘Thing2 f(bool)’:
TestCPP0x.cpp:23: note: synthesized method ‘Thing2::Thing2(const Thing2&)’
first required here

This is despite that Thing2 defines no constructors at all apart from the
default. Ok, so I tried manually disabling the lvalue constructor in Thing2
like this:

class Thing2 : public Thing {
public:
    Thing2() { }
    Thing2(Thing2&& o) : Thing(o) { }
private:
    Thing2(const Thing2&);
};

... and now I get:

ned@kate:~/Tornado/Tn/TClient/TnFOX$ g++ -o TestCPP0x -std=c++0x TestCPP0x.cpp
TestCPP0x.cpp: In constructor ‘Thing2::Thing2(Thing2&&)’:
TestCPP0x.cpp:9: error: ‘Thing::Thing(const Thing&)’ is private
TestCPP0x.cpp:15: error: within this context

In other words, the rvalue constructor in Thing2 is trying to invoke the lvalue
constructor in Thing!!! This is surely utterly wrong unless Thing has no rvalue
constructor. Our Thing class has the lvalue disabled and rvalue enabled, so GCC
is surely making a big mistake.

This is the shortest example of what went wrong with my exception throwing
problem.

There's an additional problem. If I don't specify any constructors at all for
Thing2 apart the default constructor, GCC /should/ generate synthesised ones
based on what's available in the parent classes. Unfortunately, GCC is ignoring
that the lvalue constructor has been disabled and tries to generate a lvalue
constructor anyway which is obviously doomed to failure.

GCC 3.4.1 just went into the Ubuntu repositories, so I'll try that next.

Niall


-- 


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


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

* [Bug c++/36461] [c++0x] Exception throws don't use rvalue reference constructors
  2008-06-07 20:19 [Bug c++/36461] New: [C++-0X] Exception throws don't use rvalue reference constructors s_gccbugzilla at nedprod dot com
  2008-06-08 17:08 ` [Bug c++/36461] [c++0x] " s_gccbugzilla at nedprod dot com
  2008-06-08 17:19 ` s_gccbugzilla at nedprod dot com
@ 2008-06-08 17:20 ` s_gccbugzilla at nedprod dot com
  2008-09-24 20:21 ` dgregor at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: s_gccbugzilla at nedprod dot com @ 2008-06-08 17:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from s_gccbugzilla at nedprod dot com  2008-06-08 17:19 -------
Created an attachment (id=15733)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15733&action=view)
Failing


-- 


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


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

* [Bug c++/36461] [c++0x] Exception throws don't use rvalue reference constructors
  2008-06-07 20:19 [Bug c++/36461] New: [C++-0X] Exception throws don't use rvalue reference constructors s_gccbugzilla at nedprod dot com
                   ` (2 preceding siblings ...)
  2008-06-08 17:20 ` s_gccbugzilla at nedprod dot com
@ 2008-09-24 20:21 ` dgregor at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: dgregor at gcc dot gnu dot org @ 2008-09-24 20:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from dgregor at gcc dot gnu dot org  2008-09-24 20:20 -------
GCC is doing the right thing here. In this constructor:

  Thing2(Thing2&& o) : Thing(o) { }

the parameter "o" is treated as an lvalue, because it has a name. Using
std::move(o) to treat it as an rvalue.

Similarly, there are no automatically generated move constructors or
move-assignment operators, so if you leave Thing2() empty, you'll just get the
copy constructor and therefore do a copy.


-- 

dgregor at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2008-09-24 20:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-07 20:19 [Bug c++/36461] New: [C++-0X] Exception throws don't use rvalue reference constructors s_gccbugzilla at nedprod dot com
2008-06-08 17:08 ` [Bug c++/36461] [c++0x] " s_gccbugzilla at nedprod dot com
2008-06-08 17:19 ` s_gccbugzilla at nedprod dot com
2008-06-08 17:20 ` s_gccbugzilla at nedprod dot com
2008-09-24 20:21 ` dgregor at gcc dot gnu dot 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).