$ cat init.cc ; g++4x init.cc ; g++4x -v struct X { int m; }; void f(int n) { const X *p = new const X[1] () ; } init.cc: In function void f(int): init.cc:8: error: invalid use of array with unspecified bounds init.cc:8: error: invalid use of array with unspecified bounds init.cc:8: error: invalid use of array with unspecified bounds init.cc:8: error: invalid use of array with unspecified bounds Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: ../gcc-4.x/configure --prefix=/home/redi/gcc/4.x --enable-languages=c,c++ --with-system-zlib --enable-threads=posix --enable-__cxa_atexit --disable-checking --enable-concept-checks --enable-pch --enable-libstdcxx-debug Thread model: posix gcc version 4.1.0 20050819 (experimental)
The error is only given if the array length is a positive constant expression. Negative or zero constant expressions and non-constant expressions don't trigger the error. The error is not given if X has no member, or if an array of ints is created instead of an array of X. -- Summary: new declarator with constant expression gives "error: invalid use of array with unspecified bounds" Product: gcc Version: 4.1.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: redi at gcc dot gnu dot org CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23491