[llvm-bugs] [Bug 44540] New: Inheriting from vector of move-only type leads to copy constructor being used

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jan 14 04:36:43 PST 2020


https://bugs.llvm.org/show_bug.cgi?id=44540

            Bug ID: 44540
           Summary: Inheriting from vector of move-only type leads to copy
                    constructor being used
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: weiss at wsoptics.de
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

The following code does not compile with clang + libstdc++:

#include <vector>

struct MoveOnly
{
        MoveOnly() = default;
        MoveOnly(MoveOnly const &) = delete;
        MoveOnly(MoveOnly &&) = default;
        MoveOnly & operator=(MoveOnly const &) = delete;
        MoveOnly & operator=(MoveOnly &&) = default;
};

template <typename T>
class V : public std::vector<T>
{
        using std::vector<T>::vector;

        explicit V(std::vector<T> const & v) : std::vector<T>(v) {}

        explicit V(std::vector<T> && v) : std::vector<T>(std::move(v)) {}
};

void f()
{
        V<MoveOnly> v{};
}


It does however compile with gcc and also with clang + libc++.  (But then again
not with MSVC.)

I think there's no reason for the copy constructor to be used here though.

See also

https://godbolt.org/z/m_G99y

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200114/eaf60ec4/attachment.html>


More information about the llvm-bugs mailing list