Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 75045 - gcc incorrectly accepts multiple definitions of template function
Summary: gcc incorrectly accepts multiple definitions of template function
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] GCC Porting (show other bugs)
Hardware: x86 Linux
: High minor (vote)
Assignee: Please assign to toolchain
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-20 06:20 UTC by Mattias Flodin
Modified: 2005-07-15 08:01 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mattias Flodin 2004-12-20 06:20:31 UTC
When incorrectly defining a template function belonging to a namespace, gcc 3.4.3 interprets the extra definitions as overloads and ignores additional redefinitions of the same function.

Code to reproduce:

namespace NS {
    void f();
}


template<typename T>
void f()
{
}

// This is not a member of namespace 'NS', but compiler accepts it.
template<typename T>
void NS::f()
{
}

// This definition should cause an error since it is identical to the first one.
template<typename T>
void f()
{
}

Some observations:
  * If the broken NS::f function definition is moved to the end of the file, gcc correctly reports the multiple definition, but still says nothing about the broken definition.
  * If code is added to call f<int>() the compiler reports an ambiguous overload, even though the NS namespace is not part of the current scope (and to my knowledge, Koenig lookup does not apply):
    error: call of overloaded `f()' is ambiguous
    note: candidates are: void NS::f()
    note: void f()

gcc -v output:
Reading specs from /usr/lib/gcc/i686-pc-linux-gnu/3.4.3/specs
Configured with: /var/tmp/portage/gcc-3.4.3-r1/work/gcc-3.4.3/configure --enable-version-specific-runtime-libs --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/3.4.3 --includedir=/usr/lib/gcc/i686-pc-linux-gnu/3.4.3/include --datadir=/usr/share/gcc-data/i686-pc-linux-gnu/3.4.3 --mandir=/usr/share/gcc-data/i686-pc-linux-gnu/3.4.3/man --infodir=/usr/share/gcc-data/i686-pc-linux-gnu/3.4.3/info --with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/3.4.3/include/g++-v3 --host=i686-pc-linux-gnu --disable-altivec --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --with-system-zlib --disable-checking --disable-werror --disable-libunwind-exceptions --enable-shared --enable-threads=posix --disable-multilib --disable-libgcj --enable-languages=c,c++,f77
Thread model: posix
gcc version 3.4.3 20041125 (Gentoo Linux 3.4.3-r1, ssp-3.4.3-0, pie-8.7.7)

emerge info output:
Portage 2.0.51-r8 (default-linux/x86/2004.3, gcc-3.4.3, glibc-2.3.4.20041102-r0, 2.6.9-gentoo-r6 i686)
=================================================================
System uname: 2.6.9-gentoo-r6 i686 Intel(R) Pentium(R) M processor 1300MHz
Gentoo Base System version 1.6.8
Python:              dev-lang/python-2.3.4 [2.3.4 (#1, Nov 18 2004, 15:54:33)]
ccache version 2.3 [enabled]
dev-lang/python:     2.3.4
sys-devel/autoconf:  2.59-r5
sys-devel/automake:  1.8.5-r1
sys-devel/binutils:  2.15.92.0.2-r2
sys-devel/libtool:   1.5.10
virtual/os-headers:  2.6.8.1-r1
ACCEPT_KEYWORDS="x86 ~x86"
AUTOCLEAN="yes"
CFLAGS="-O3 -march=pentium4 -fomit-frame-pointer -fprefetch-loop-arrays -fforce-addr -funroll-loops -pipe"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/X11R6/lib/X11/xkb /usr/kde/2/share/config /usr/kde/3/share/config /usr/lib/mozilla/defaults/pref /usr/share/config /usr/share/texmf/dvipdfm/config/ /usr/share/texmf/dvips/config/ /usr/share/texmf/tex/generic/config/ /usr/share/texmf/tex/platex/config/ /usr/share/texmf/xdvi/ /var/qmail/control"CONFIG_PROTECT_MASK="/etc/gconf /etc/terminfo /etc/env.d"
CXXFLAGS="-O3 -march=pentium4 -fomit-frame-pointer -fprefetch-loop-arrays -fforce-addr -funroll-loops -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="autoaddcvs autoconfig ccache distlocks fixpackages sandbox sfperms"
GENTOO_MIRRORS="ftp://ftp.du.se/pub/os/gentoo http://ftp.du.se/pub/os/gentoo ftp://mirror.pudas.net/gentoo http://mirror.pudas.net/gentoo ftp://ftp.tu-clausthal.de/pub/linux/gentoo/"
MAKEOPTS="-j2"
PKGDIR="/usr/portage/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY=""
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="X aalib acpi alsa apache2 avi bitmap-fonts bonobo canna cdr cjk crypt cscope dga dvd encode f77 fam flac foomaticdb ggi gif gnome gpm gstreamer gtk gtk2 gtkhtml imagemagick imlib jikes jpeg libg++ libwww mad mmx motif mpeg ncurses nls nptl oggvorbis pam pdflib png python quicktime readline samba sdl slang spell sqlite sse ssl tetex tiff truetype unicode usb videos wmf wxwindows x86 xml xml2 xmms xv xvid zlib"
Comment 1 Caleb Tennis (RETIRED) gentoo-dev 2005-07-15 08:01:10 UTC
Seems like something that should be reports to gnu.gcc.org