public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/18267] New: external linkage of functions declared in an anonymous namespace
@ 2004-11-01 18:30 TazForEver at dlfp dot org
  2004-11-01 19:05 ` [Bug c++/18267] " pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: TazForEver at dlfp dot org @ 2004-11-01 18:30 UTC (permalink / raw)
  To: gcc-bugs

Here are 3 functions and a dummy main:

--begin--
int one() { return 1; }

static int two() { return 2; }

namespace
{
  int three() { return 3; }
}

int main()
{
  return one() + two() + three();
}
--end--

i was expecting that g++ handled two() and three() the same way, that
is to say generated object-code with internal linkage.
 
But g++ doesn't. three() has external linkage, just like one(). TCPPPL
says that an anonymous namespace is a namespace with a unique
name. Fine. Then why g++ does not optimize this ?  The previous
program returns 6. g++ outputs a definition for three(), but it is
obvious that two() and three() definitions are no longer needed
because they've been inlined. That's why g++ doesn't output a
definition for two(). In the end, i get a never-used definition of
three() ...

Thanks

>>> LC_ALL=C g++-3.4 -v
Reading specs from /usr/lib/gcc/powerpc-linux/3.4.2/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,pascal,objc,ada --prefix=/usr
--libexecdir=/usr/lib --with-gxx-include-dir=/usr/include/c++/3.4
--enable-shared --with-system-zlib --enable-nls --without-included-gettext
--program-suffix=-3.4 --enable-__cxa_atexit --enable-libstdcxx-allocator=mt
--enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm
--enable-java-awt=gtk --disable-multilib --disable-multilib powerpc-linux
Thread model: posix
gcc version 3.4.2 (Debian 3.4.2-3)

-- 
           Summary: external linkage of functions declared in an anonymous
                    namespace
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: TazForEver at dlfp dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18267


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-11-02 16:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-01 18:30 [Bug c++/18267] New: external linkage of functions declared in an anonymous namespace TazForEver at dlfp dot org
2004-11-01 19:05 ` [Bug c++/18267] " pinskia at gcc dot gnu dot org
2004-11-01 23:52 ` giovannibajo at libero dot it
2004-11-02  0:10 ` TazForEver at dlfp dot org
2004-11-02  0:19 ` giovannibajo at libero dot it
2004-11-02  0:48 ` TazForEver at dlfp dot org
2004-11-02  1:22 ` giovannibajo at libero dot it
2004-11-02  1:53 ` bangerth at dealii dot org
2004-11-02  9:21 ` TazForEver at dlfp dot org
2004-11-02 11:55 ` giovannibajo at libero dot it
2004-11-02 16:10 ` bangerth at dealii dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).