[Bug c++/71218] New: Add a warning about "new T[integer-literal]"

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sat May 21 13:28:00 GMT 2016


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

            Bug ID: 71218
           Summary: Add a warning about "new T[integer-literal]"
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

There is no reason anyone should ever write:

  T* p = new T[8];
  ...
  delete[] p;

The compiler should issue a warning telling them to stop being silly.

It should probably only trigger for integer literals, because a variable or a
macro might be constant in some build configurations and not in others. But an
integer literal that isn't the result of macro-expansion is just silly.


More information about the Gcc-bugs mailing list