G++ rejects the following valid code, claiming that 'void A::Thingo()' is a redeclaration of 'typedef int Thingo'. The error goes away if: - you wrap the typedef in an anonymous namespace; - you include the definition of void A::Thingo() in namespace A. The error remains if: - you replace the typedef with enum { Thingo }; ---- test.cc ---- typedef int Thingo; namespace A { void Thingo(); } void A::Thingo() { ; } int main() { A::Thingo(); return 0; } ---- EOF ---- $ g++ test.cc test.cc: In function `void A::Thingo()': test.cc:11: `void A::Thingo()' redeclared as different kind of symbol test.cc:1: previous declaration of `typedef int Thingo' $ g++ -v Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/u sr/share/info --enable-shared --enable-threads=posix --disable-checking --with-s ystem-zlib --enable-__cxa_atexit --host=i386-redhat-linux Thread model: posix gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
Confired. What an odd bug, I'm surprised nobody ever hit that before. It used to work in 2.95, but is broken in 3.0.x, 3.2.x, 3.3.x and mainline. This certainly counts as a serious regression. W.
This has been failing since at least 2000-12-31.
Subject: Bug 12862 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2003-12-22 23:57:09 Modified files: gcc : ChangeLog c-common.c c-common.h c-opts.c gcc/cp : ChangeLog decl.c decl2.c lex.c name-lookup.c pt.c gcc/doc : invoke.texi gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/lookup: ns1.C Removed files: gcc/testsuite/g++.old-deja/g++.jason: template18.C template37.C Log message: * c-common.c (flag_external_templates): Remove. (flag_alt_external_templates): Likewise. * c-common.h (flag_external_templates): Remove. (flag_alt_external_templates): Likewise. * c-opts.c (c_common_handle_option): Unsupport -falt-external-templates and -ftemplates. * doc/invoke.texi: Remove mention of -fexternal-templates and -falt-external-templates. * decl.c (start_function): Do not check flag_alt_external_templates or flag_external_templates. * decl2.c (warn_if_unknown_interface): Likewise. * lex.c (extract_interface_info): Likewise. * pt.c (lookup_template_class): Likewise. PR c++/12862 * name-lookup.c (pushdecl): Look up all namespace-scope entities in their corresponding namespace. * g++.old-deja/g++.jason/template18.C: Remove. * g++.old-deja/g++.jason/template37.C: Likewise. PR c++/12862 * g++.dg/lookup/ns1.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.2078&r2=2.2079 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-common.c.diff?cvsroot=gcc&r1=1.469&r2=1.470 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-common.h.diff?cvsroot=gcc&r1=1.213&r2=1.214 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-opts.c.diff?cvsroot=gcc&r1=1.95&r2=1.96 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3831&r2=1.3832 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1166&r2=1.1167 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&r1=1.691&r2=1.692 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/lex.c.diff?cvsroot=gcc&r1=1.321&r2=1.322 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.29&r2=1.30 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.806&r2=1.807 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/doc/invoke.texi.diff?cvsroot=gcc&r1=1.369&r2=1.370 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3301&r2=1.3302 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/ns1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.jason/template18.C.diff?cvsroot=gcc&r1=1.10&r2=NONE http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.jason/template37.C.diff?cvsroot=gcc&r1=1.6&r2=NONE
Fixed in GCC 3.4.
Not yet fixed in GCC 3.3.x.
Will backport patch from mainline
Subject: Bug 12862 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: gdr@gcc.gnu.org 2003-12-26 03:20:21 Modified files: gcc/cp : ChangeLog decl.c Added files: gcc/testsuite/g++.dg/lookup: ns1.C Log message: Backport from mainline: 2003-12-22 Mark Mitchell <mark@codesourcery.com> PR C++/12862 * decl.c (pushdecl): Look up all namespace-scope entities in their corresponding namespace. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/ns1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.4.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.227&r2=1.3076.2.228 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.965.2.64&r2=1.965.2.65
fixed.