0

Following this answer and this move-constructor specification, there should be no implicit move constructor or move assignment operator.

However, the following code still compiles in gcc 7.2.1:

#include <vector>
#include <iostream>
using namespace std;

struct NoCopyNoMove
{
    NoCopyNoMove(const NoCopyNoMove&) = delete;
    NoCopyNoMove& operator=(const NoCopyNoMove&) = delete;
    NoCopyNoMove(NoCopyNoMove&&) = delete;
    NoCopyNoMove& operator=(NoCopyNoMove&&) = delete;

    NoCopyNoMove(int){};
};

struct NoCopy
{
    NoCopy(const NoCopyNoMove&) = delete;
    NoCopy& operator=(const NoCopyNoMove&) = delete;
    // NoCopy(NoCopy&&) = delete;
    // NoCopy& operator=(NoCopy&&) = delete;
    ~NoCopy() {
        std::cout << "decontructor" << std::endl;
    }
    NoCopy(int){};
};

int main()
{
    // vector<NoCopyNoMove> y; // fails!
    vector<NoCopy> y;
    y.emplace_back(1);
    y.emplace_back(2);
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
youwei
  • 49
  • 7

1 Answers1

5

You have a typo in your code. Where you have:

NoCopy(const NoCopyNoMove&) = delete;
NoCopy& operator=(const NoCopyNoMove&) = delete;

You should instead have:

NoCopy(const NoCopy&) = delete;
NoCopy& operator=(const NoCopy&) = delete;

Make those changes and the code indeed fails to compile:

https://wandbox.org/permlink/lVhPkL6ioLTC9k1w

Paul Sanders
  • 24,133
  • 4
  • 26
  • 48