From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1F70C3850436; Thu, 10 Dec 2020 17:05:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1F70C3850436 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/98216] [C++20] std::array template parameter error with negative values Date: Thu, 10 Dec 2020 17:05:07 +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: 11.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org 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: Thu, 10 Dec 2020 17:05:08 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98216 --- Comment #2 from Jonathan Wakely --- Reduced: template struct array { constexpr T& operator[](int n) { return d[n]; } constexpr const T& operator[](int n) const { return d[n]; } constexpr bool operator=3D=3D(const array& a) const { for (int i =3D 0; i < N; ++i) if (d[i] !=3D a.d[i]) return false; return true; } T d[N]; }; using an_array =3D array ; constexpr auto add_array (an_array a, an_array const& b) { a[0] +=3D b[0]; return a; } template struct wrapper { static constexpr auto arr =3D A; }; template auto add (wrapper const&, wrapper const&) { return wrapper {}; } constexpr auto ONE =3D an_array {{ 1. }}; constexpr auto MINUS_ONE =3D an_array {{ -1. }};=20 constexpr auto MINUS_TWO =3D an_array {{ -2. }};=20 int main () { auto a =3D wrapper {}; auto b =3D wrapper {}; auto c =3D add (a, b); __builtin_printf("%f %f %f\n", a.arr[0], b.arr[0], c.arr[0]); if (c.arr !=3D MINUS_ONE) __builtin_abort(); } Prints: -2.000000 1.000000 -2.000000 Aborted (core dumped)=