From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5240B385609A; Tue, 14 Jun 2022 09:32:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5240B385609A From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/105957] __n * sizeof(_Tp) might overflow under consteval context for std::allocator Date: Tue, 14 Jun 2022 09:32:44 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: accepts-invalid 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: keywords everconfirmed bug_status cf_reconfirmed_on 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: Tue, 14 Jun 2022 09:32:44 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105957 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |accepts-invalid Ever confirmed|0 |1 Status|UNCONFIRMED |NEW Last reconfirmed| |2022-06-14 --- Comment #1 from Jonathan Wakely --- Testcase: #include constexpr auto f() { std::allocator a; auto n =3D std::size_t(-1) / (sizeof(long long) - 1); auto p =3D a.allocate(n); a.deallocate(p, n); return n; } static_assert( f() ); In practice if the arithmetic wraps around and a smaller buffer is allocate= d, any attempt to write beyond the allocated size would be detected in constant evaluation anyway. So you'd still get a compilation error in most cases.=