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

Pavel Černohorský via cfe-users cfe-users at lists.llvm.org
Thu Nov 5 07:07:30 PST 2020


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 <source>:1:
> /opt/compiler-explorer/gcc-10.2.0/lib/gcc/x86_64-linux-gnu/10.2.0/../../../../include/c++/10.2.0/optional:158:7: 
> error: the parameter for this explicitly-defaulted copy assignment 
> operator is const, but a member or base requires it to be non-const
>      operator=(const _Optional_payload_base&) = default;
>      ^
> /opt/compiler-explorer/gcc-10.2.0/lib/gcc/x86_64-linux-gnu/10.2.0/../../../../include/c++/10.2.0/optional:357:7: 
> note: in instantiation of template class 
> 'std::_Optional_payload_base<S>' requested here
>    : _Optional_payload_base<_Tp>
>      ^
> /opt/compiler-explorer/gcc-10.2.0/lib/gcc/x86_64-linux-gnu/10.2.0/../../../../include/c++/10.2.0/optional:631:30: 
> note: in instantiation of template class 'std::_Optional_payload<S, 
> true, false, false>' requested here
>      _Optional_payload<_Tp> _M_payload;
>                             ^
> /opt/compiler-explorer/gcc-10.2.0/lib/gcc/x86_64-linux-gnu/10.2.0/../../../../include/c++/10.2.0/optional:660:15: 
> note: in instantiation of template class 'std::_Optional_base<S, true, 
> true>' requested here
>    : private _Optional_base<_Tp>,
>              ^
> <source>:10:20: note: in instantiation of template class 
> 'std::optional<S>' requested here
>  std::optional<S> a;
>                   ^
> 1 error generated.
>
I got exactly the same error, but the question is why. Shouldn't both 
g++ and clang++ behave the same way even on the libstdc++ (which is the 
default library clang uses on a lot of distros)? Is this gcc being too 
permissive to some bug in libstdc++ or is it a clang bug? Should I file 
a bug report to clang?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20201105/152de9ef/attachment.html>


More information about the cfe-users mailing list