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

            Bug ID: 107528
           Summary: constexpr evaluator doesn't check for deallocate of
                    mismatched size
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vanyacpp at gmail dot com
  Target Milestone: ---

This functions causes undefined behavior and should not be evaluated at
compile-time.

The problem is the second argument of `deallocate` function (number of objects
to deallocate). It must be equal to the number of objects that were allocated.

#include <memory>

constexpr int foo()
{
    std::allocator<int> alloc;
    int* p = alloc.allocate(1);
    alloc.deallocate(p, 3);
    return 42;
}

static_assert(foo() == 42);

Reply via email to