From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14577 invoked by alias); 19 Sep 2007 17:47:41 -0000 Received: (qmail 14492 invoked by uid 48); 19 Sep 2007 17:47:30 -0000 Date: Wed, 19 Sep 2007 17:47:00 -0000 Subject: [Bug c++/33501] New: Copy constructor assumed to exist for undefined class X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "ciobi at inbox dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-09/txt/msg01606.txt.bz2 GCC 4.2.1 assumes that undefined classes have public copy constructors (at least when they are used in template classes), as evidenced in the code below. GCC 4.1.0 generates a compiler error for the same code. -------------------- begin gcc_error2.cpp ------------------------ class A; template struct X { static int f(T); static const T& make(); static const bool value = sizeof(f(make())) == sizeof(int); }; int main() { return X::value; } --------------------- end gcc_error2.cpp ------------------------- ================================================================ Command line: g++ -v -save-temps gcc_error2.cpp Using built-in specs. Target: x86_64-suse-linux Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.2.1 --enable-ssp --disable-libssp --disable-libgcj --with-slibdir=/lib64 --with-system-zlib --enable-shared --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --program-suffix=-4.2 --enable-version-specific-runtime-libs --without-system-libunwind --with-cpu=generic --host=x86_64-suse-linux Thread model: posix gcc version 4.2.1 (SUSE Linux) /usr/lib64/gcc/x86_64-suse-linux/4.2.1/cc1plus -E -quiet -v -D_GNU_SOURCE gcc_error2.cpp -mtune=generic -fpch-preprocess -o gcc_error2.ii #include "..." search starts here: #include <...> search starts here: /usr/include/c++/4.2.1 /usr/include/c++/4.2.1/x86_64-suse-linux /usr/include/c++/4.2.1/backward /usr/local/include /usr/lib64/gcc/x86_64-suse-linux/4.2.1/include /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/include /usr/include End of search list. /usr/lib64/gcc/x86_64-suse-linux/4.2.1/cc1plus -fpreprocessed gcc_error2.ii -quiet -dumpbase gcc_error2.cpp -mtune=generic -auxbase gcc_error2 -version -o gcc_error2.s GNU C++ version 4.2.1 (SUSE Linux) (x86_64-suse-linux) compiled by GNU C version 4.2.1 (SUSE Linux). GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=128517 Compiler executable checksum: c51aed1e29693425775d4f74be6f0e18 /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/bin/as -V -Qy -o gcc_error2.o gcc_error2.s GNU assembler version 2.17.50.0.5 (x86_64-suse-linux) using BFD version 2.17.50.0.5 20060927 (SUSE Linux) /usr/lib64/gcc/x86_64-suse-linux/4.2.1/collect2 --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.2.1/crtbegin.o -L/usr/lib64/gcc/x86_64-suse-linux/4.2.1 -L/usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../.. gcc_error2.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib64/gcc/x86_64-suse-linux/4.2.1/crtend.o /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../lib64/crtn.o ================================================================ The preprocessed source (although in this particular case I don't see any use for it): -------------------- begin gcc_error2.ii ------------------------- # 1 "gcc_error2.cpp" # 1 "" # 1 "" # 1 "gcc_error2.cpp" class A; template struct X { static int f(T); static const T& make(); static const bool value = sizeof(f(make())) == sizeof(int); }; int main() { return X::value; } --------------------- end gcc_error2.ii -------------------------- ================================================================ I tested this on OpenSUSE 10.2 but I'm pretty sure it's not OS-dependent. I became aware of this issue as a result of a post by Nicola Musatti in "comp.lang.c++.moderated" on 2007-09-06, called "Is this valid code?" ( http://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/56c346896185e23e ). The code in gcc_error2.cpp is a simplified version of that presented there. The last post as of 2007-09-17 is by Daveed Vandevoorde and I think it implies that this is a bug in GCC 4.2.1. ================================================================ (Sorry if the format is not appropriate. I tried to follow the guidelines at http://gcc.gnu.org/bugs.html and http://gcc.gnu.org/bugzilla/page.cgi?id=bug-writing.html, but they seem to be out of synch with the actual web form used for adding bug reports, which doesn't seem to provide any place besides the "description" field to enter the compiler output or the preprocessed file.) -- Summary: Copy constructor assumed to exist for undefined class Product: gcc Version: 4.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ciobi at inbox dot com GCC build triplet: x86_64-suse-linux GCC host triplet: x86_64-suse-linux GCC target triplet: x86_64-suse-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33501