From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id AEE96386EC54; Sat, 19 Dec 2020 22:17:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AEE96386EC54 From: "wjwray at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/93480] Defaulted <=> doesn't expand array elements Date: Sat, 19 Dec 2020 22:17:29 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: wjwray at gmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Dec 2020 22:17:29 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D93480 --- Comment #2 from Will Wray --- For reference, here's a macro-free workaround to provide portable operator<=3D> for templated classes with array members, defaulting where possible (current Clang and MSVC) otherwise dispatching to a user-defined implementation (current gcc) https://godbolt.org/z/qbEfh7 First, a trait to check default 3-way array compare: inline constexpr bool has_default_array_compare =3D [] { struct C { char c[1]; auto operator<=3D>(C const&) const =3D default; }; return std::three_way_comparable; }(); Then constrain the operator<=3D> definitions template struct array { T data[N]; friend auto operator<=3D>(array const&, array const&) requires has_default_array_compare =3D default; friend constexpr auto operator<=3D>(array const& l, array const& r) requires (!has_default_array_compare) { return compare_three_way{}(l.data,r.data); } }; However, this only works for templated classes as it is not (yet) allowed to constrain non-template functions.=