https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67913
            Bug ID: 67913
           Summary: new expression with negative size not diagnosed
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

A new expression is considered erroneous if the expression in its
noptr-new-declarator is of non-class type and its value before converting to
std::size_t is less than zero.  If the expression is a constant expression, the
program is ill-fomed.  The following program contains two such ill-formed
expressions is not diagnosed by GCC.

void* operator new[] (unsigned long, void *p) { return p; }

void foo (void)
{
    char c;
    new char [-1];
    new (&c) char [-1];
}

Clang issues the following warnings for it:

a.cpp:6:15: warning: array size is negative [-Wbad-array-new-length]
    new char [-1];
              ^~
a.cpp:7:20: warning: array size is negative [-Wbad-array-new-length]
    new (&c) char [-1];
                   ^~
2 warnings generated.

Reply via email to