https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99018
Bug ID: 99018 Summary: Comparing address of array element not considered a constant expression in certain contexts Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: david at doublewise dot net Target Milestone: --- The following valid translation unit ``` struct s { constexpr s() = default; constexpr s(s const & other) { if (this == &other) { } } }; constexpr auto f() { s init[2]; for (auto & element : init) { s foo = element; } return true; } static_assert(f()); ``` is rejected by gcc with ``` <source>:18:16: error: non-constant condition for static assertion 18 | static_assert(f()); | ~^~ <source>:18:16: in 'constexpr' expansion of 'f()' <source>:13:11: in 'constexpr' expansion of 's((*(const s*)(& element)))' <source>:5:26: error: '(((const s*)(& foo)) == (((const s*)(& init)) + 1))' is not a constant expression 5 | if (this == &other) { | ~~~~~^~~~~~~~~ Compiler returned: 1 ``` See it live: https://godbolt.org/z/xG5dv5