-1

Why the clang says call to deleted constructor of 'Block<Tuple>::Self' (aka 'Block<Tuple>') in the call of Block<Tuple>::a1() when I delete the move constructor?

c++17 clang version 9.0.0 (tags/RELEASE_900/final) Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin

template<typename tRecord>
struct Block {

    using Self = Block<tRecord>;

    Size mUsedBytes;
    bool mModified;

    union Data {
        char mBytes[4_KB];
        tRecord mRecord;
    };
    Data mData;

    Block() {
        mardCpp::Log::info("constructing");
    };

    Block(const Block &block) = delete;
    Block(Block &&block) = delete;

    static Self a1() {
        Self block;
        return block;
    }

    static Self a2() {
        return Self();
    }
};

From what I've readed, I could have garanteed rvo if I deleted the copy and move constructors. The compiler would complain in situations where he could not do rvo and the code would not compile. For instance, when I delete the copy constructor and define the move one with just throwing an error, he actually optimizes the calling of a1, since I got no errors. But when I delete the move constructor, the code does not even compile.

4

1 回答 1

0

这段代码:

static Self a1() {
    Self block;
    return block;
}

不是所谓的“保证复制省略”的一部分。它仍然具有与旧版本 C++ 相同的行为,即它是复制省略上下文,但复制/移动构造必须有效且编译器不必执行省略。

a2代码是“保证”的,因此您不应该从中得到错误。

于 2019-10-20T21:50:43.150 回答