[Bug c++/95772] New: warning desired when default operator= cannot be constructued
marcpawl at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Jun 19 20:14:36 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95772
Bug ID: 95772
Summary: warning desired when default operator= cannot be
constructued
Product: gcc
Version: 10.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: marcpawl at gmail dot com
Target Milestone: ---
https://godbolt.org/z/eXckPe
#include <type_traits>
class Const {
public:
int const i_;
Const(int i) : i_(i) {}
Const& operator=(Const& rhs) = default;
};
int main(int argc, char**) {
Const c{argc};
static_assert(!std::is_assignable<Const, Const>::value,
"should not be able to assign i_");
#ifdef ASSIGN
Const d{argc + 1};
d = c;
#endif
return c.i_;
}
I expected a diagnostic saying that operator= cannot be defaulted which is seen
if the ASSIGN code is enabled. The code compiles cleanly.
When I wrote this bug in a large code base with -03 and -flto the code will
fail with illegal instructions and other memory corruption errors. No problem
without optimization.
More information about the Gcc-bugs
mailing list