<div dir="ltr"><div dir="ltr">On Thu, 5 Nov 2020 at 09:29, Marshall Clow via cfe-users <<a href="mailto:cfe-users@lists.llvm.org">cfe-users@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Nov 5, 2020, at 6:34 AM, Pavel Černohorský via cfe-users <<a href="mailto:cfe-users@lists.llvm.org" target="_blank">cfe-users@lists.llvm.org</a>> wrote:<br>
> <br>
> Hello,<br>
> <br>
> I would like to ask what is wrong with the following code:<br>
> ```<br>
> <br>
> #include <optional><br>
> <br>
> struct S<br>
> {<br>
> S& operator=(S&) { return *this; };<br>
> };<br>
> <br>
> void thisWillNotCompileInClang()<br>
> {<br>
> std::optional<S> a;<br>
> }<br>
> <br>
> ```<br>
> <br>
> Compilation command is `g++ or clang++ -std=c++17 -c source.cpp`. It compiles without problems with g++ 9.3.0, but not with clang++ 10.0.0 (both from current stable Ubuntu 20). This code is simplification of code using widely adopted rapidjson library which uses assignment operator with non-const parameter a lot. Earlier versions of clang did not complain (tried with 7.0.1 on currently stable Debian Buster).<br>
<br>
A note from the libstdc++ maintainer:<br>
<br>
> I think there was a core change in C++20 to make the =default do the right thing (which is delete it, I think).<br>
> Clang does compile it with -std=c++20 just not -std=c++17.<br></blockquote><div><br></div><div>Right, this was made valid by P0641R2, which was voted into C++20 but was not moved as a defect report resolution against prior standards. So I think g++ is being more permissive than the standard requires (though as far as I can see, it would be a conforming extension to accept these cases retroactively), and libstdc++ seems to be relying on that lenience (probably unintentionally).</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
— Marshall<br>
<br>
<br>
_______________________________________________<br>
cfe-users mailing list<br>
<a href="mailto:cfe-users@lists.llvm.org" target="_blank">cfe-users@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users</a><br>
</blockquote></div></div>