[cfe-users] Code which compiles with g++ but not with clang++

2020-11-05 Thread Pavel Černohorský via cfe-users
Hello, I would like to ask what is wrong with the following code: ``` #include struct S {    S& operator=(S&) { return *this; }; }; void thisWillNotCompileInClang() {   std::optional a; } ``` Compilation command is `g++ or clang++ -std=c++17 -c source.cpp`. It compiles without problems wit

Re: [cfe-users] Code which compiles with g++ but not with clang++

2020-11-05 Thread Marshall Clow via cfe-users
> On Nov 5, 2020, at 6:34 AM, Pavel Černohorský via cfe-users > wrote: > > Hello, > > I would like to ask what is wrong with the following code: > ``` > > #include > > struct S > { > S& operator=(S&) { return *this; }; > }; > > void thisWillNotCompileInClang() > { > std::optional a; > }

Re: [cfe-users] Code which compiles with g++ but not with clang++

2020-11-05 Thread Pavel Černohorský via cfe-users
On 05. 11. 20 15:47, Marshall Clow via cfe-users wrote: I tried this code on compiler explorer. It compiles w/o error with clang + libc++ It fails to compile with clang and libstdc++ The error message given is: In file included from :1: /opt/compiler-explorer/gcc-10.2.0/lib/gcc/x86_64-linux-gnu

Re: [cfe-users] Code which compiles with g++ but not with clang++

2020-11-05 Thread connor horman via cfe-users
On Thu, Nov 5, 2020 at 11:06 connor horman wrote: > Looking at https://eel.is/c++draft/optional.optional and optional.assign, > it shouldn't be ill-formed to have a non copy-constructible type, the copy > constructor of optional should be defined as deleted. > [optional.optional.general] clause 3

Re: [cfe-users] Code which compiles with g++ but not with clang++

2020-11-05 Thread connor horman via cfe-users
I've actually reduced the problem to the defaulted copy assignment operator itself: gcc: https://godbolt.org/z/83Gjdb clang: https://godbolt.org/z/z35x4K The controlling clause would seem to be https://eel.is/c++draft/class.copy.assign#7.4. In particular, because overload resolution cannot find th

Re: [cfe-users] Code which compiles with g++ but not with clang++

2020-11-05 Thread Marshall Clow via cfe-users
On Nov 5, 2020, at 6:34 AM, Pavel Černohorský via cfe-users wrote: > > Hello, > > I would like to ask what is wrong with the following code: > ``` > > #include > > struct S > { >S& operator=(S&) { return *this; }; > }; > > void thisWillNotCompileInClang() > { > std::optional a; > } >