This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52069] ARM: initialization of static member in template struct
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 31 Jan 2012 15:47:40 +0000
- Subject: [Bug c++/52069] ARM: initialization of static member in template struct
- Auto-submitted: auto-generated
- References: <bug-52069-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52069
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-01-31 15:47:40 UTC ---
The program is ill-formed:
"If a template, a member template or a member of a class template is explicitly
specialized then that specialization shall be declared before the first use of
that specialization that would cause an implicit instantiation to take place,
in every translation unit in which such a use occurs; no diagnostic is
required."
When compiling main.o the compiler has no way to know that you have explicitly
instantiated S<T>::id so it is implicitly instantiated.
You need to declare the explicit instantiation in tmpl.h
template<> struct ID S<T>::id;
That will prevent the implicit instantiation of that member in main.o, and your
explicit instantiation in libtmpl.so will be used.