This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/6564: -frepo with function template in anonymous namespace fails to compile



>Number:         6564
>Category:       c++
>Synopsis:       -frepo with function template in anonymous namespace fails to compile
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Sun May 05 10:16:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Shimshon Duvdevan
>Release:        gcc version 3.0.4, Thread model: posix
>Organization:
>Environment:
sparc-sun-solaris2.6 (bug irrelevant to platform)
>Description:
A function template is defined in anonymous namespace,
and is called from global namespace. When trying to compile
with -frepo, the recompiling/relinking goes on indefinitely,
until done 17 times (regardless of -ftemplate-depth-n):
[these are the commands for the first example, second
 is similar]

$ g++ -frepo -Wall -c -o anon.o anon.C
$ g++ -frepo -Wall -o anon anon.o                       
collect: recompiling anon.C
collect: relinking
collect: recompiling anon.C
collect: relinking
collect: recompiling anon.C
collect: relinking
collect: recompiling anon.C
collect: relinking
collect: recompiling anon.C
collect: relinking
collect: recompiling anon.C
collect: relinking
collect: recompiling anon.C
collect: relinking
collect: recompiling anon.C
collect: relinking
collect: recompiling anon.C
collect: relinking
collect: recompiling anon.C
collect: relinking
collect: recompiling anon.C
collect: relinking
collect: recompiling anon.C
collect: relinking
collect: recompiling anon.C
collect: relinking
collect: recompiling anon.C
collect: relinking
collect: recompiling anon.C
collect: relinking
collect: recompiling anon.C
collect: relinking
collect: recompiling anon.C
collect: relinking
Undefined                       first referenced
 symbol                             in file
void (anonymous namespace)::foo<int>(int)anon.o
ld: fatal: Symbol referencing errors. No output written to anon
collect2: ld returned 1 exit status
>How-To-Repeat:
[anon.C - first example]
namespace {
  template <typename Tp>
  void foo(Tp) {}
}

int
main()
{
  foo(int());
}

[anon2.C - second example]
namespace {
  struct Foo {};
}

template <typename Tp>
void foo(Tp) {}

int
main()
{
  foo(Foo());
}
>Fix:
Inlining the function explicitly or implicitly (via -O3)
makes the problem go away, but only because the function is,
well, inlined.

Using static qualifier instead of the anonymous namespace
fixes the problem in the first case, but then there are
scenarios that are not fixable in this way, such as a function
template (not in anonymous namespace), whose parameter is
a class which is defined in an anonymous namespace, see
second example.
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]