[Bug c++/93016] New: erroneous new (nothrow_t) still throws an exception

barry.revzin at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu Dec 19 18:09:00 GMT 2019


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

            Bug ID: 93016
           Summary: erroneous new (nothrow_t) still throws an exception
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

Reduced from SO (https://stackoverflow.com/q/59414654/2069064):

#include <new>

int f()
{
    int n = -1;
    try {
        int *p = new(std::nothrow) int[n];
        if (!p) return 0;
    } catch (const std::bad_array_new_length&) {
        return 1;
    }

    return 2;
}

This function returns 1 (because the new expression throws
bad_array_new_length), it should return 0 (because the "allocation function
that would have been called has a non-throwing exception specification").


More information about the Gcc-bugs mailing list