Boost logo

Boost :

Subject: [boost] [contract] auto_..._error regression tests fail on C++1z
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2017-09-28 22:58:57

Hello all,

I asked this question on compl.c++ list as well, given this is more of
a general C++1z question than a Boost question. However, this is
making some Boost.Contract regression tests fail on C++1z compilers so
I wanted to ask it here as well hoping to get some info more

Following code prevents copies outside its friend function f:

    // File: 05.cpp

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

        friend x f();

    x f() { return x(); }

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

Correctly it does not compile up to C++1y because main cannot access
the copy operations:

    $ clang++ -std=c++1y 05.cpp
    05.cpp:14:15: error: calling a private constructor of class 'x'
        auto xx = f();
    05.cpp:5:5: note: declared private here
        x(x const&) {}
    1 error generated.

However, it compiles on C++1z?!

    $ clang++ -std=c++1z 05.cpp
    # Not compiler errors?!

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?


Boost list run by bdawes at, gregod at, cpdaniel at, john at