public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-105957-4-cLJvhf86yT@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-105957-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105957

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-06-14

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Testcase:

#include <memory>

constexpr auto f()
{
  std::allocator<long long> a;
  auto n = std::size_t(-1) / (sizeof(long long) - 1);
  auto p = a.allocate(n);
  a.deallocate(p, n);
  return n;
}
static_assert( f() );


In practice if the arithmetic wraps around and a smaller buffer is allocated,
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.

  reply	other threads:[~2022-06-14  9:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-13 19:10 [Bug libstdc++/105957] New: " unlvsur at live dot com
2022-06-14  9:32 ` redi at gcc dot gnu.org [this message]
2022-06-14 20:19 ` [Bug libstdc++/105957] " cvs-commit at gcc dot gnu.org
2022-06-14 20:20 ` redi at gcc dot gnu.org
2022-08-03 13:46 ` cvs-commit at gcc dot gnu.org
2022-08-03 13:49 ` redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-105957-4-cLJvhf86yT@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).