public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54509] New: If Move constructor is templatized then it is invoked else not
@ 2012-09-06 20:10 rsdevgun at gmail dot com
  2012-09-07  5:38 ` [Bug c++/54509] " daniel.kruegler at googlemail dot com
  2012-09-07  8:31 ` redi at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: rsdevgun at gmail dot com @ 2012-09-06 20:10 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 54509
           Summary: If Move constructor is templatized then it is invoked
                    else not
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: rsdevgun@gmail.com


#include <iostream>
#include <string>

using namespace std;
// uncomment to see the bug with 4.7.1 and 4.8.0
#define _BUG_

struct Test
{
  Test() = default;
  Test(const Test & )
  {
    cout << "ctor overload 1 & " << endl;
  }

  #ifdef _BUG_

  template<typename T>
  Test(T && )
  {
    //T* t = "0"; // For intentional error
    cout << "ctor template version overload 2 && " << endl;
  }

  #else
  Test(Test && )
  {
    cout << "ctor specialized overload 2 && " << endl;
  }

  #endif
 };



int main()
{
  Test t1( []()-> Test { return Test();}() );

  return 0;
}








I expect Test(Test && ) to be invokved (without template version).

Also if you uncommment //T* t = "0"; -> you will see that data type is not a
magical data type, Being same as class itself, behavior is wrong.


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

* [Bug c++/54509] If Move constructor is templatized then it is invoked else not
  2012-09-06 20:10 [Bug c++/54509] New: If Move constructor is templatized then it is invoked else not rsdevgun at gmail dot com
@ 2012-09-07  5:38 ` daniel.kruegler at googlemail dot com
  2012-09-07  8:31 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-09-07  5:38 UTC (permalink / raw)
  To: gcc-bugs

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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler at
                   |                            |googlemail dot com

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-09-07 05:37:56 UTC ---
The language requires that the presence of a user-declared copy-constructor
(which you have used in your code) shall prevent the compiler-declared move
constructor. When _BUG_ is defined, the effect is that the class has a copy
constructor and a template constructor

template<typename T>
Test(T &&);

but *no* move constructor. The template constructor will always be a better
match for rvalue arguments than the copy constructor, therefore it is called
twice in your program.

In other words: The behavior of gcc looks correct and this report seems invalid
to me.


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

* [Bug c++/54509] If Move constructor is templatized then it is invoked else not
  2012-09-06 20:10 [Bug c++/54509] New: If Move constructor is templatized then it is invoked else not rsdevgun at gmail dot com
  2012-09-07  5:38 ` [Bug c++/54509] " daniel.kruegler at googlemail dot com
@ 2012-09-07  8:31 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2012-09-07  8:31 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-09-07 08:31:25 UTC ---
as Daniel said


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

end of thread, other threads:[~2012-09-07  8:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-06 20:10 [Bug c++/54509] New: If Move constructor is templatized then it is invoked else not rsdevgun at gmail dot com
2012-09-07  5:38 ` [Bug c++/54509] " daniel.kruegler at googlemail dot com
2012-09-07  8:31 ` 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).