https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111284
Bug ID: 111284 Summary: Some passing-by-value parameters are miscompiled since GCC 9 Product: gcc Version: 13.2.0 Status: UNCONFIRMED Keywords: accepts-invalid, rejects-valid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: de34 at live dot cn Target Milestone: --- GCC incorrectly rejects the following program since GCC 9 (https://godbolt.org/z/cGK1a1dqK): ``` class self_locator { public: self_locator() = default; constexpr self_locator(const self_locator&) noexcept : this_{this} {} constexpr self_locator& operator=(const self_locator&) noexcept { return *this; } constexpr bool valid() const noexcept { return this_ == this; } private: self_locator *this_ = this; }; constexpr bool demonstrator(self_locator x) noexcept { return x.valid(); } static_assert(demonstrator(self_locator{}), ""); static_assert([](self_locator x){ return x.valid(); }(self_locator{}), ""); ``` The `valid` member function should always return true. But if `self_locator` is passed by value, GCC can sometimes render the parameter in an inconsistent state (perhaps due to incorrect bitwise copy).