[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 06:34:23 PST 2020
Hello,
I would like to ask what is wrong with the following code:
```
#include <optional>
struct S
{
S& operator=(S&) { return *this; };
};
void thisWillNotCompileInClang()
{
std::optional<S> a;
}
```
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).
Thank you very much for your time and explanation. Kind regards,
Pavel Cernohorsky
More information about the cfe-users
mailing list