public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/46246] New: [C++0x] Move constructor required when passing a temporary by copy, but not actually used
@ 2010-10-30 16:27 a.pignotti at sssup dot it
  2010-10-30 16:29 ` [Bug c++/46246] " a.pignotti at sssup dot it
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: a.pignotti at sssup dot it @ 2010-10-30 16:27 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: [C++0x] Move constructor required when passing a
                    temporary by copy, but not actually used
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: a.pignotti@sssup.it


Created attachment 22208
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22208
test case that fails to compile

The attached test case causes a compiler error, GCC seems to need the
unavailable move constructor even if a


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

* [Bug c++/46246] [C++0x] Move constructor required when passing a temporary by copy, but not actually used
  2010-10-30 16:27 [Bug c++/46246] New: [C++0x] Move constructor required when passing a temporary by copy, but not actually used a.pignotti at sssup dot it
@ 2010-10-30 16:29 ` a.pignotti at sssup dot it
  2010-10-30 16:31 ` a.pignotti at sssup dot it
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: a.pignotti at sssup dot it @ 2010-10-30 16:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Alessandro Pignotti <a.pignotti at sssup dot it> 2010-10-30 16:28:49 UTC ---
Created attachment 22209
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22209
test case that shows that the move constructor is not actually used


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

* [Bug c++/46246] [C++0x] Move constructor required when passing a temporary by copy, but not actually used
  2010-10-30 16:27 [Bug c++/46246] New: [C++0x] Move constructor required when passing a temporary by copy, but not actually used a.pignotti at sssup dot it
  2010-10-30 16:29 ` [Bug c++/46246] " a.pignotti at sssup dot it
@ 2010-10-30 16:31 ` a.pignotti at sssup dot it
  2010-10-31 10:01 ` paolo.carlini at oracle dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: a.pignotti at sssup dot it @ 2010-10-30 16:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Alessandro Pignotti <a.pignotti at sssup dot it> 2010-10-30 16:31:27 UTC ---
The secondo attachment compiles, but the move constructor seems not really
used. The output is:

default bar
foo called

Moreover i was expecting a call to the copy constructor but that was elided, is
this an optimization or something mandated by the standard?


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

* [Bug c++/46246] [C++0x] Move constructor required when passing a temporary by copy, but not actually used
  2010-10-30 16:27 [Bug c++/46246] New: [C++0x] Move constructor required when passing a temporary by copy, but not actually used a.pignotti at sssup dot it
  2010-10-30 16:29 ` [Bug c++/46246] " a.pignotti at sssup dot it
  2010-10-30 16:31 ` a.pignotti at sssup dot it
@ 2010-10-31 10:01 ` paolo.carlini at oracle dot com
  2010-10-31 12:05 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-10-31 10:01 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-10-31 10:00:51 UTC ---
Let's add Jason in CC..


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

* [Bug c++/46246] [C++0x] Move constructor required when passing a temporary by copy, but not actually used
  2010-10-30 16:27 [Bug c++/46246] New: [C++0x] Move constructor required when passing a temporary by copy, but not actually used a.pignotti at sssup dot it
                   ` (2 preceding siblings ...)
  2010-10-31 10:01 ` paolo.carlini at oracle dot com
@ 2010-10-31 12:05 ` redi at gcc dot gnu.org
  2010-10-31 13:28 ` paolo.carlini at oracle dot com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2010-10-31 12:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-31 12:05:00 UTC ---
Copy elision is an optimisation allowed by the standard, but not mandated.

-fno-elide-constructors to disable it, then you should see the move constructor
called for the second test case.

The relevant constructor must be accessible and callable even if it is elided.


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

* [Bug c++/46246] [C++0x] Move constructor required when passing a temporary by copy, but not actually used
  2010-10-30 16:27 [Bug c++/46246] New: [C++0x] Move constructor required when passing a temporary by copy, but not actually used a.pignotti at sssup dot it
                   ` (3 preceding siblings ...)
  2010-10-31 12:05 ` redi at gcc dot gnu.org
@ 2010-10-31 13:28 ` paolo.carlini at oracle dot com
  2010-10-31 15:10 ` a.pignotti at sssup dot it
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-10-31 13:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-10-31 13:28:14 UTC ---
Makes sense, of course (I'm not used to private or protected deleted members).
Thus looks like this can closed as invalid?


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

* [Bug c++/46246] [C++0x] Move constructor required when passing a temporary by copy, but not actually used
  2010-10-30 16:27 [Bug c++/46246] New: [C++0x] Move constructor required when passing a temporary by copy, but not actually used a.pignotti at sssup dot it
                   ` (4 preceding siblings ...)
  2010-10-31 13:28 ` paolo.carlini at oracle dot com
@ 2010-10-31 15:10 ` a.pignotti at sssup dot it
  2010-11-01  0:15 ` redi at gcc dot gnu.org
  2010-11-01 14:17 ` jason at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: a.pignotti at sssup dot it @ 2010-10-31 15:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Alessandro Pignotti <a.pignotti at sssup dot it> 2010-10-31 15:10:22 UTC ---
Please consider the first test case before declaring this bug invalid. I think
should be legal to delete the move construtor and still being able to pass
temporaries by copy.


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

* [Bug c++/46246] [C++0x] Move constructor required when passing a temporary by copy, but not actually used
  2010-10-30 16:27 [Bug c++/46246] New: [C++0x] Move constructor required when passing a temporary by copy, but not actually used a.pignotti at sssup dot it
                   ` (5 preceding siblings ...)
  2010-10-31 15:10 ` a.pignotti at sssup dot it
@ 2010-11-01  0:15 ` redi at gcc dot gnu.org
  2010-11-01 14:17 ` jason at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2010-11-01  0:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-11-01 00:15:33 UTC ---
No, a deleted function can still be selected by overload resolution. Defining a
move constructor as deleted does not have the semantics you want.

In the current draft, n3126, a user-declared copy constructor suppresses the
implicit declaration of a move constructor.  So all you need to do to make a
class copyable but not movable is declare the copy constructor.  Don't declare
a move constructor, definitely don't define it as deleted.


$ cat foo.cpp
#include <iostream>

using namespace std;

class Bar
{
public:
        Bar()
        {
                cout << "default bar" << endl;
        }
        Bar(const Bar& r)
        {
                cout << "copy bar" << endl;
        }
};

void foo(Bar p)
{
        cout << "foo called" << endl;
}

int main()
{
        foo(Bar());
        return 0;
}
$ g++ -std=c++0x foo.cpp -fno-elide-constructors
$ ./a.out
default bar
copy bar
foo called


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

* [Bug c++/46246] [C++0x] Move constructor required when passing a temporary by copy, but not actually used
  2010-10-30 16:27 [Bug c++/46246] New: [C++0x] Move constructor required when passing a temporary by copy, but not actually used a.pignotti at sssup dot it
                   ` (6 preceding siblings ...)
  2010-11-01  0:15 ` redi at gcc dot gnu.org
@ 2010-11-01 14:17 ` jason at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2010-11-01 14:17 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

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

--- Comment #8 from Jason Merrill <jason at gcc dot gnu.org> 2010-11-01 14:17:04 UTC ---
Jonathan is correct.


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

end of thread, other threads:[~2010-11-01 14:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-30 16:27 [Bug c++/46246] New: [C++0x] Move constructor required when passing a temporary by copy, but not actually used a.pignotti at sssup dot it
2010-10-30 16:29 ` [Bug c++/46246] " a.pignotti at sssup dot it
2010-10-30 16:31 ` a.pignotti at sssup dot it
2010-10-31 10:01 ` paolo.carlini at oracle dot com
2010-10-31 12:05 ` redi at gcc dot gnu.org
2010-10-31 13:28 ` paolo.carlini at oracle dot com
2010-10-31 15:10 ` a.pignotti at sssup dot it
2010-11-01  0:15 ` redi at gcc dot gnu.org
2010-11-01 14:17 ` jason 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).