This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/45755] New: Member function template is instantiated to perform the copy


"A member function template is never instantiated to perform the copy of a
class object to an object of its
class type."

But gcc instantiates it if function parameter type is the rvalue reference.
Following code shall not output anything if executed.

struct S
{
    S() = default ;

    template < typename T >
    S( T && ) { std::cout << "bad constructor" << std::endl ; }

    template < typename T >
    S & operator = ( T && ){ std::cout << "bad assignment operator" <<
std::endl ; return *this ; }
} ;

int main()
{
    S a ;

    S b = a ; // must use trivial copy constructor
    b = a ; // must use trivial assignment operator
}

But gcc instantiate and call bad constructor and assignment operator to perform
the copy.


-- 
           Summary: Member function template is instantiated to perform the
                    copy
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: boostcpp at gmail dot com


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]