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; }
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.
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.
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
The code is right. mainline produces a bogus error (which is covered 11027) and 3.3 should instantiate the symbol. W.
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.
Stupid browser I want this to be add again.
*** Bug 11384 has been marked as a duplicate of this bug. ***
The problem is that the FSF's gcc does not support weak symbols on Darwin.
Target-specific.
*** Bug 12830 has been marked as a duplicate of this bug. ***
*** Bug 14234 has been marked as a duplicate of this bug. ***
Fixed for 3.5.0.
Andrew, which patch fixed this? There is no mention in the comments.
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
*** Bug 21060 has been marked as a duplicate of this bug. ***
*** Bug 25107 has been marked as a duplicate of this bug. ***