Bug 11026 - [Darwin] g++ does not instantiate static data members of templates
Summary: [Darwin] g++ does not instantiate static data members of templates
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.3
: P2 enhancement
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
: 11384 12830 14234 21060 25107 (view as bug list)
Depends on: 11303
Blocks:
  Show dependency treegraph
 
Reported: 2003-05-29 11:01 UTC by John Maddock
Modified: 2005-11-26 18:30 UTC (History)
7 users (show)

See Also:
Host: powerpc-apple-darwin6
Target: powerpc-apple-darwin6
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-01-01 21:24:10


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Maddock 2003-05-29 11:01:16 UTC
The summary says it all, on MAC OS X, g++ fails to instantiate static data 
members of class templates even when they are clearly used, the following test 
program illustrates the issue (this is currently something of a showstopper 
for boost.regex):


#include <assert.h>

template <class T>
struct test
{
   int run(int);

   typedef int (test::*callback_type)(int);

   int c1(int);
   int c2(int);

   static callback_type s_callbacks[];
};

template <class T>
int test<T>::run(int i)
{
   if(!&s_callbacks)assert(0);
   callback_type c = s_callbacks[i];
   return (this->*c)(i);
}

template <class T>
int test<T>::c1(int i)
{
   return i;
}

template <class T>
int test<T>::c2(int i)
{
   return ++i;
}

template <class T>
typename test<T>::callback_type test<T>::s_callbacks[] = 
{
   &test<T>::c1, 
   &test<T>::c2,
};

int main()
{
   test<int> i;
   assert(i.run(0) == 0);
   return 0;
}
Comment 1 Wolfgang Bangerth 2003-05-29 13:56:38 UTC
Am I right that the summary line of this report should actually read
"...does NOT instantiate..."?

Apart from that, can you please say what exactly happens on your
platform (I suspect you want to imply that it doesn't link, but 
you're not exactly verbose on this). Also, can you post the output
of "gcc -v"?

Thanks
  Wolfgang

For reference: compiles fine with 3.3 on x86 linux, it fails with
present mainline, though. The failure is unrelated, and I have just
submitted it as PR 11027.
Comment 2 John Maddock 2003-05-30 10:30:30 UTC
You are correct: I meant to say does *not* instantiate...

The compiler output is:

bash-2.05a$ g++ test.cpp
ld: Undefined symbols:
test<int>::s_callbacks

I have tested this myself with:

bash-2.05a$ g++ -v
Reading specs from /usr/libexec/gcc/darwin/ppc/3.1/specs
Thread model: posix
Apple Computer, Inc. GCC version 1175, based on gcc version 3.1 20020420 
(prerelease)

However the problem was originally reported to me with a more recent gcc 
release (3.2 I think).

As you correctly note this is not an issue on any other gcc platform I have 
tried (solaris, linux, cygwin).

Thanks,

John Maddock.
Comment 3 Dara Hazeghi 2003-06-01 00:08:48 UTC
Hello,

On darwin, with gcc 3.3 branch, we get an ICE:
test.cpp: In member function `int test<T>::run(int) [with T = int]':
test.cpp:20: internal compiler error: in int_mode_for_mode, at stor-layout.c:
   295

with gcc mainline (20030527), we get an error:
test.cpp:37: error: conflicting types for `typename test<T>::callback_type 
   test<T>::s_callbacks[]'
test.cpp:13: error: previous declaration as `int 
   (test<T>::*test<T>::s_callbacks[])(int)'

on i686-linux, the code compiles and runs fine on both gcc 3.2 and 3.3 branch, but mainline gives 
the same error as it did on Darwin. So now to the experts: is gcc mainline right, or is the code 
right?

Dara
Comment 4 Wolfgang Bangerth 2003-06-01 00:41:21 UTC
The code is right. mainline produces a bogus error (which is covered 11027)
and 3.3 should instantiate the symbol.

W.
Comment 5 Andrew Pinski 2003-06-24 05:37:00 UTC
I get ICE now on the mainline (20030623). The same ICE Dara got with the 3.3 branch:
pr11026.cc: In member function `int test<T>::run(int) [with T = int]':
pr11026.cc:19: internal compiler error: in int_mode_for_mode, at stor-layout.c:
   304
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
I will filed a new bug for that ICE which is only on powerpc-apple-darwin6.6 (might also 
be on powerpc-* but I have not test yet.
Comment 6 Andrew Pinski 2003-06-24 05:44:05 UTC
Stupid browser I want this to be add again.
Comment 7 Andrew Pinski 2003-07-20 13:23:15 UTC
*** Bug 11384 has been marked as a duplicate of this bug. ***
Comment 8 Andrew Pinski 2003-07-20 13:23:50 UTC
The problem is that the FSF's gcc does not support weak symbols on Darwin.
Comment 9 Nathanael C. Nerode 2003-08-03 18:27:33 UTC
Target-specific.
Comment 10 Andrew Pinski 2003-10-29 19:53:48 UTC
*** Bug 12830 has been marked as a duplicate of this bug. ***
Comment 11 Andrew Pinski 2004-02-23 02:13:06 UTC
*** Bug 14234 has been marked as a duplicate of this bug. ***
Comment 12 Andrew Pinski 2004-03-16 16:03:48 UTC
Fixed for 3.5.0.
Comment 13 Giovanni Bajo 2004-03-17 03:36:54 UTC
Andrew, which patch fixed this? There is no mention in the comments.
Comment 14 Andrew Pinski 2004-03-17 03:41:03 UTC
This was fixed by:
2004-03-12  Matt Austern  <austern@apple.com>
        
        * target.h (struct gcc_target): New target hook, unwind_label.
        * target-def.h (TARGET_ASM_EMIT_UNWIND_LABEL): New hook.
        * output.h (default_emit_unwind_label): New function.
        * default.h (TARGET_EXPLICIT_INSTANTIATIONS_ONE_ONLY): New macro.
        (TARGET_USES_WEAK_UNWIND_INFO): New target macro.
        (TARGET_SUPPORTS_HIDDEN): New target macro.
        * dwarf2out.c (struct dw_fde_struct): Add field for function decl
        that corresponds to this FDE.
        (FRAME_BEGIN_LABEL): Allow target to override default label.
        (output_call_frame_info): If FDEs are linknonce, then use extra
        indirection for FDE encoding, output a label for each FDE, and
        output an empty label for each function without an FDE.
        (dwarf2out_begin_prologue): Set up decl field when creating an FDE.
        * varasm.c (globalize_decl): Call ASM_MAKE_LABEL_LINKONCE for
       .... more
Comment 15 Andrew Pinski 2005-04-16 19:05:58 UTC
*** Bug 21060 has been marked as a duplicate of this bug. ***
Comment 16 Andrew Pinski 2005-11-26 18:30:26 UTC
*** Bug 25107 has been marked as a duplicate of this bug. ***