This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/8371: Self initialization
- From: jorgen at profitab dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 27 Oct 2002 23:03:53 -0000
- Subject: c++/8371: Self initialization
- Reply-to: jorgen at profitab dot com
>Number: 8371
>Category: c++
>Synopsis: Self initialization
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: accepts-illegal
>Submitter-Id: net
>Arrival-Date: Sun Oct 27 15:06:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: jorgen@profitab.com
>Release: gcc version 3.2.1 20021020 (Debian prerelease)
>Organization:
>Environment:
Linux Debian GNU/Linux sid/unstable
>Description:
I've found a possible illegal statement in the C++ compiler as well as the C compiler. I detected the problem first using g++ (C++), but discovered that the same behaviour can be seen using gcc (C).
Self initialization is legal according to the compilers. As I don't have the language reference manual, nor did I find anything on the net, I'm inclined to believe this is a bug. It does not make sense to allow self initialization. At the very least, the compiler should issue a warning. No such warning is issued with -Wall.
Not only did I find this in the Debian gcc 3.2.1 compiler, I also found it in the Debian 2.95.4 20011002 (prerelease) compiler as well as in the OpenBSD 2.95.3 20010125 (prerelease) compiler.
Attached is a single file containing the C++ source for reproducing the error as well as the output from the command "g++-3.2 -Wall -v -save-temps tst.cpp". No preprocessed files are attached as I'm not including any header files.
>How-To-Repeat:
Extract the C++ code from the attached file and compile it using -Wall. No warnings - no errors.
Of course, the variable x contains garbage - verify with std::cout.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="bugreport.txt"
Content-Disposition: inline; filename="bugreport.txt"
C++ Source begins here:
int main(void) {
int x = x;
return 0;
}
Output from g++ -Wall -v -save-temps tst.cpp here:
Reading specs from /usr/lib/gcc-lib/i386-linux/3.2.1/specs
Configured with: /mnt/data/gcc-3.1/gcc-3.2-3.2.1ds3/src/configure -v --enable-languages=c,c++,java,f77,proto,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-java-gc=boehm --enable-objc-gc i386-linux
Thread model: posix
gcc version 3.2.1 20021020 (Debian prerelease)
/usr/lib/gcc-lib/i386-linux/3.2.1/cpp0 -lang-c++ -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -v -D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=1 -D__GXX_ABI_VERSION=102 -D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -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_i386__ tst.cpp -Wall tst.ii
GNU CPP version 3.2.1 20021020 (Debian prerelease) (cpplib) (i386 Linux/ELF)
ignoring nonexistent directory "/usr/i386-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/3.2
/usr/include/c++/3.2/i386-linux
/usr/include/c++/3.2/backward
/usr/local/include
/usr/lib/gcc-lib/i386-linux/3.2.1/include
/usr/include
End of search list.
/usr/lib/gcc-lib/i386-linux/3.2.1/cc1plus -fpreprocessed tst.ii -quiet -dumpbase tst.cpp -Wall -version -o tst.s
GNU CPP version 3.2.1 20021020 (Debian prerelease) (cpplib) (i386 Linux/ELF)
GNU C++ version 3.2.1 20021020 (Debian prerelease) (i386-linux)
compiled by GNU C version 3.2.1 20021020 (Debian prerelease).
as -V -Qy -o tst.o tst.s
GNU assembler version 2.13.90.0.10 (i386-linux) using BFD version 2.13.90.0.10 20021010 Debian GNU/Linux
/usr/lib/gcc-lib/i386-linux/3.2.1/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/gcc-lib/i386-linux/3.2.1/../../../crt1.o /usr/lib/gcc-lib/i386-linux/3.2.1/../../../crti.o /usr/lib/gcc-lib/i386-linux/3.2.1/crtbegin.o -L/usr/lib/gcc-lib/i386-linux/3.2.1 -L/usr/lib/gcc-lib/i386-linux/3.2.1/../../.. tst.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc-lib/i386-linux/3.2.1/crtend.o /usr/lib/gcc-lib/i386-linux/3.2.1/../../../crtn.o