This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/69879] New: Create a pointer to the default operator new and delete


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

            Bug ID: 69879
           Summary: Create a pointer to the default operator new and
                    delete
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daniel.gutson at tallertechnologies dot com
  Target Milestone: ---

This issue comes from the following discussion:

https://gcc.gnu.org/ml/libstdc++/2015-11/msg00009.html

In short: Pedro Alves suggested as a solution the addition of a pointer to the
original (default) operator new and another for the operator delete, e.g.
__default_operator_new and __default_operator_delete.
This will allow users to override the global operators new and delete, and yet
call the original implementations, for example to alter the behavior when there
is no memory and the nothrow new should not iterate calling the new_handler.

// Example 1:

void* operator new  ( std::size_t count, const std::nothrow_t& tag)
noexcept(true)
{
    const auto old_handler = std::set_new_handler(nullptr);
    const auto ret = __default_operator_new(count, tag);
    std::set_new_handler(old_handler);
    return ret;
}


// Slightly different example:

void* operator new  ( std::size_t count, const std::nothrow_t& tag)
noexcept(true)
{
    const auto old_handler = std::set_new_handler(nullptr);
    const auto ret = __default_operator_new(count, tag);
    std::set_new_handler(old_handler);

    if (ret == nullptr && old_handler != nullptr)
        old_handler();

    return ret;
}

Please assign this to aurelio.remonda@tallertechnologies.com

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]