public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/3084: anonymous namespace linking
@ 2001-06-08  4:56 conversy
  0 siblings, 0 replies; 3+ messages in thread
From: conversy @ 2001-06-08  4:56 UTC (permalink / raw)
  To: gcc-gnats

>Number:         3084
>Category:       c++
>Synopsis:       anonymous namespace linking
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Fri Jun 08 04:56:02 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     conversy@emn.fr
>Release:        gcc version 3.0 20010426 (Debian prerelease)
>Organization:
>Environment:
i386-linux
>Description:
anonymous namespace functions cannot be linked
to global call to these functions.

There is an error when linking an object file with
the code of a function declared inside a unnamed
"namespace {}".

In the .o that includes the function code, the name
is the form *__GLOBAL__* where in the .o that refers
to the function code, the name is different.


>How-To-Repeat:
g++ AB.cpp test.cpp

gives: undefined reference to `(anonymous namespace)::operator<<(std::ostream&, (anonymous namespace)::A const&)'


AB.h:

namespace std {
  struct ostream {};
  extern ostream cout;
};

namespace {
  struct A {};
  std::ostream& operator<<(std::ostream&, const A&);
}

namespace foo {
  struct B {};
}

std::ostream& operator<<(std::ostream&, const foo::B&);

AB.cpp:
#include "AB.h"

namespace {
  std::ostream& operator<<(std::ostream& out, const A&) { return out; }
}

std::ostream& operator<<(std::ostream& out, const foo::B&) { return out; }

test.cpp:
#include "AB.h"

main()
{
  A a;
  std::cout << a;
  foo::B b;
  std::cout << b;
}




>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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

* Re: c++/3084: anonymous namespace linking
@ 2001-07-11 10:44 mmitchel
  0 siblings, 0 replies; 3+ messages in thread
From: mmitchel @ 2001-07-11 10:44 UTC (permalink / raw)
  To: conversy, gcc-bugs, gcc-prs, nobody

Synopsis: anonymous namespace linking

State-Changed-From-To: open->closed
State-Changed-By: mmitchel
State-Changed-When: Wed Jul 11 10:44:20 2001
State-Changed-Why:
    Not a bug.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=3084&database=gcc


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

* Re: c++/3084: anonymous namespace linking
@ 2001-06-08  6:26 Artem Khodush
  0 siblings, 0 replies; 3+ messages in thread
From: Artem Khodush @ 2001-06-08  6:26 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/3084; it has been noted by GNATS.

From: "Artem Khodush" <artem@duma.gov.ru>
To: <conversy@emn.fr>
Cc: <gcc-gnats@gcc.gnu.org>, <gcc-bugs@gcc.gnu.org>
Subject: Re: c++/3084: anonymous namespace linking
Date: Fri, 8 Jun 2001 16:48:55 +0400

 > anonymous namespace functions cannot be linked
 > to global call to these functions.
 > 
 > There is an error when linking an object file with
 > the code of a function declared inside a unnamed
 > "namespace {}".
 > 
 > In the .o that includes the function code, the name
 > is the form *__GLOBAL__* where in the .o that refers
 > to the function code, the name is different.
 > 
 
 This is not a bug, this behavior is requred by the c++ 
 standard, and is the very reason of existence of
 unnamed namespaces.
  
 7.3.1.1 - Unnamed namespaces [namespace.unnamed]
 -1- An unnamed-namespace-definition behaves as if it were 
 replaced by 
 
 namespace 'unique' { /* empty body */ }
 using namespace 'unique';
 namespace 'unique' { namespace-body }
 
 where all occurrences of 'unique' in a translation unit are 
 replaced by the same identifier and this identifier differs 
 from all other identifiers in the entire program.* 
 
 [Footnote: Although entities in an unnamed namespace 
 might have external linkage, they are effectively qualified 
 by a name unique to their translation unit and therefore 
 can never be seen from any other translation unit. 
 --- end footnote]
 
 
 
 


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

end of thread, other threads:[~2001-07-11 10:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-08  4:56 c++/3084: anonymous namespace linking conversy
2001-06-08  6:26 Artem Khodush
2001-07-11 10:44 mmitchel

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).