Boost logo

Boost :

Subject: Re: [boost] [contract] auto_..._error regression tests fail on C++1z
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2017-09-29 02:29:44


On Thu, Sep 28, 2017 at 4:05 PM, Niall Douglas via Boost
<boost_at_[hidden]> wrote:
>> Why... what changed in C++1z that makes the above compile? How can I
>> prevent copying x outside its friend function f in C++1z?
>
> C++ 17 guarantees copy elision in the strong sense.
>
> Note it still can't be copied, but it can be initialised now. So disable
> non-friend construction to fix.

I see. However, making the constructor private still does not make the
compilation fail. The following code compiles fine on clang++
-std=c++1z ...

struct x {
private:
    x() {}
    x(x const&) {}
    x& operator=(x const&) { return *this; }

    friend x f();
};

x f() { return x(); }

int main() {
    auto xx = f();
    return 0;
}

Is there any way to make that `auto xx = f()` in main fail at compile
time in C++1z?

Thanks,
--Lorenzo


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk