This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/5805: the expression 'new (int*)[10]' should be a syntax error
- From: Moritz Franosch <jfranosc at physik dot tu-muenchen dot de>
- To: rodrigc at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
- Date: 05 Mar 2002 10:29:57 +0100
- Subject: Re: c++/5805: the expression 'new (int*)[10]' should be a syntax error
- References: <20020303024958.3156.qmail@sources.redhat.com>
rodrigc@gcc.gnu.org writes:
> Synopsis: the expression 'new (int*)[10]' should be a syntax error
>
> State-Changed-From-To: open->closed
> State-Changed-By: rodrigc
> State-Changed-When: Sat Mar 2 18:49:58 2002
> State-Changed-Why:
> With gcc 3.0.4, I get a compilation error:
> ++-new-bug.cpp: In function `int main()':
> g++-new-bug.cpp:6: cannot convert `int*' to `int**' in assignment
Sorry, my report was confusing because I said g++ gives a warning. In
fact g++ gives an error (for line (3)), which is correct behaviour.
Nevertheless line (2) should, according to the standard, also give an
error. But g++ does not generate an error for line (2), which is a
bug.
I've tried with gcc 3.0.4 and it behaves the same as gcc 3.0.2 in this
case:
start g++-new-bug-2.cpp
int main() {
int** p;
p=new int*[10]; // 1
p=new (int*)[10]; // 2 (should be a syntax error, but seems to
// compile semantically equivalent to 1)
}
end g++-new-bug-2.cpp
jfranosc@synapse:~/tmp/g++-new-bug > /lscratch/jfranosc/gcc/local/bin/g++ -v g++-new-bug-2.cpp
Reading specs from /lscratch/jfranosc/gcc/local/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/specs
Configured with: ../gcc-3.0.4/configure --prefix=/lscratch/jfranosc/gcc/local
Thread model: single
gcc version 3.0.4
/lscratch/jfranosc/gcc/local/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/cc1plus -v -D__GNUC__=3
-D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=4 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ g++-new-bug-2.cpp -D__GNUG__=3 -D__GXX_DEPRECATED -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -quiet -dumpbase g++-new-bug-2.cpp -version -o /tmp/ccFo2S3Y.s
GNU CPP version 3.0.4 (cpplib) (i386 Linux/ELF)
GNU C++ version 3.0.4 (i686-pc-linux-gnu)
compiled by GNU C version 3.0.4.
ignoring nonexistent directory "/lscratch/jfranosc/gcc/local/i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/lscratch/jfranosc/gcc/local/include/g++-v3
/lscratch/jfranosc/gcc/local/include/g++-v3/i686-pc-linux-gnu
/lscratch/jfranosc/gcc/local/include/g++-v3/backward
/usr/local/include
/lscratch/jfranosc/gcc/local/include
/lscratch/jfranosc/gcc/local/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/include
/usr/include
End of search list.
as --traditional-format -V -Qy -o /tmp/ccKNWSeP.o /tmp/ccFo2S3Y.s
GNU assembler version 2.10.91 (i486-suse-linux) using BFD version 2.10.0.33
/lscratch/jfranosc/gcc/local/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /lscratch/jfranosc/gcc/local/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/crtbegin.o -L/lscratch/jfranosc/gcc/local/lib/gcc-lib/i686-pc-linux-gnu/3.0.4 -L/lscratch/jfranosc/gcc/local/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/../../.. /tmp/ccKNWSeP.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /lscratch/jfranosc/gcc/local/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/crtend.o /usr/lib/crtn.o
G++ 3.0.4 compiles the program (with the missing line (3)) without any
errors, as does g++ 3.0.2. But g++ should generate an error for line
(2). For the reasons why I think line (2) is a syntax error please see
my original report. I'm pretty shure that line (2) is not correct C++
because of the replies I got on comp.std.c++.
Thank you for your reply,
Moritz