Home Dashboard Directory Help
Search

Visual C++: Copy Constructor Bug for Base Class with Template Constructor by Victor Scherba


Status: 

Closed
 as Fixed Help for as Fixed


2
1
Sign in
to vote
Type: Bug
ID: 651972
Opened: 3/17/2011 5:29:12 AM
Access Restriction: Public
2
Workaround(s)
view
1
User(s) can reproduce this bug

Description

struct base
{
    base() {}

    base(const base&) {}

    template <class Other>
    base(const Other&) {}
};

struct derived : base
{
};

derived der1, der2(der1); // invokes template constuctor instead of copy constructor, what is wrong.

I have checked it on GCC and Comeau compilers, and them works without this bug.
This bug, for example, does not it possible to inherit boost::function class template properly.

I seem, when compiler generates default copy constructor for derived class it pass into base constructor parameter of a derived type considering implicit upcasting. But I can be wrong.
Details
Sign in to post a comment.
Posted by Microsoft on 9/17/2011 at 10:58 AM
Hi: this issue has been fixed. The fix should show up in a future release of Visual C++.

Thank you for reporting the issue.

Jonathan Caves
Visual C++ Compiler Team
Posted by Noah Roberts on 4/21/2011 at 9:58 AM
Probably related to a bug I posted a while back: http://connect.microsoft.com/VisualStudio/feedback/details/587787/implicit-copy-constructor-calls-base-with-derived-type-under-specific-conditions#details
Posted by Microsoft on 3/17/2011 at 8:01 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by Microsoft on 3/17/2011 at 6:13 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Cassio Neri on 11/23/2012 at 9:27 AM
Alternatively, you can SFINAE away the template constructor when Other derives from base:

#include <type_traits>

// ...

template <class Other>
base(const Other&, typename std::enable_if<!std::is_base_of<base, Other>::value>::type* = nullptr) {}
Posted by Noah Roberts on 4/21/2011 at 10:00 AM
Write a user-defined copy constructor and upcast 'other' to the base type before passing it on.
File Name Submitted By Submitted On File Size  
base_constructor_bug.cpp 3/17/2011 437 bytes