public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15394] New: g++ fails to produce a static definition for static template member
@ 2004-05-13 1:00 razeh at yahoo dot com
2004-05-13 1:30 ` [Bug c++/15394] " pinskia at gcc dot gnu dot org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: razeh at yahoo dot com @ 2004-05-13 1:00 UTC (permalink / raw)
To: gcc-bugs
I am having trouble getting gcc 3.4.0 to produce a static definition
for a static member of a template class. I have been following
the example giving in bug report 15006
(http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15006) for creating
the static definition. However, after adding a main to the sample
code that references the static variables it appears to compile but not link.
The compiler:
razeh@terk:/home/host/razeh/testing$ gcc -v
Reading specs from
/usr/local/packages/gcc-3.4.0/lib/gcc/sparc-sun-solaris2.8/3.4.0/specs
Configured with: /home/host/ewolfe/gcc-3.4.0/configure
--prefix=/usr/local/packages/gcc-3.4.0 --disable-multilib --enable-languages=c,c++
Thread model: posix
gcc version 3.4.0
The test case:
template<class K, class V> class EST_THash;
class EST_String
{
public:
void foobar() { }
};
class EST_Regex
{
public:
void bar() { }
};
template<class K, class V>
class EST_THash {
public:
static V Dummy_Value;
static K Dummy_Key;
};
template <> EST_Regex * EST_THash< EST_String, EST_Regex * >::Dummy_Value;
template <> EST_String EST_THash< EST_String, EST_Regex * >::Dummy_Key;
template EST_Regex * EST_THash< EST_String, EST_Regex * >::Dummy_Value;
template EST_String EST_THash< EST_String, EST_Regex * >::Dummy_Key;
int main(int argc, char *argv[])
{
EST_THash<EST_String, EST_Regex*> foo;
foo.Dummy_Value->bar();
}
The problem:
razeh@terk:/home/host/razeh/testing$ g++ missingStatic3.C
Undefined first referenced
symbol in file
EST_THash<EST_String, EST_Regex*>::Dummy_Value /var/tmp//cccPQZFu.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
--
Summary: g++ fails to produce a static definition for static
template member
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: razeh at yahoo dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: sparc-sun-solaris2.8/
GCC host triplet: sparc-sun-solaris2.8/
GCC target triplet: sparc-sun-solaris2.8/
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15394
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/15394] g++ fails to produce a static definition for static template member
2004-05-13 1:00 [Bug c++/15394] New: g++ fails to produce a static definition for static template member razeh at yahoo dot com
@ 2004-05-13 1:30 ` pinskia at gcc dot gnu dot org
2004-05-13 1:42 ` bangerth at dealii dot org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-13 1:30 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-05-12 13:48 -------
That is because I was wrong you have to supply the full template declaration for the variables like the
following:
template <class K, class V> V EST_THash< K, V >::Dummy_Value;
template <class K, class V> K EST_THash< K, V >::Dummy_Key;
template EST_Regex * EST_THash< EST_String, EST_Regex * >::Dummy_Value;
template EST_String EST_THash< EST_String, EST_Regex * >::Dummy_Key;
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15394
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/15394] g++ fails to produce a static definition for static template member
2004-05-13 1:00 [Bug c++/15394] New: g++ fails to produce a static definition for static template member razeh at yahoo dot com
2004-05-13 1:30 ` [Bug c++/15394] " pinskia at gcc dot gnu dot org
@ 2004-05-13 1:42 ` bangerth at dealii dot org
2004-05-13 13:34 ` giovannibajo at libero dot it
2005-06-26 14:55 ` pinskia at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: bangerth at dealii dot org @ 2004-05-13 1:42 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-05-12 13:55 -------
No, Andrew, you are wrong again, but the code is invalid anyway. What
happens is that
template <> type Class<type>::member;
declares the existence of an explicit specialization of the member variable.
You can do that, there is no requirement that only the completely
unspecialized template class member variable can be declared. However, since
this syntax is the _declaration_ of a variable, not a _definition_, you get
a linker error. To make it a definition, you have to give the variable
declaration an initializer, i.e. do something like
template <> type Class<type>::member = 1;
or (if you want the default initialization):
template <> type Class<type>::member = type();
This will yield a _definition_ and should make the linker error go away.
Wolfgang
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15394
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/15394] g++ fails to produce a static definition for static template member
2004-05-13 1:00 [Bug c++/15394] New: g++ fails to produce a static definition for static template member razeh at yahoo dot com
2004-05-13 1:30 ` [Bug c++/15394] " pinskia at gcc dot gnu dot org
2004-05-13 1:42 ` bangerth at dealii dot org
@ 2004-05-13 13:34 ` giovannibajo at libero dot it
2005-06-26 14:55 ` pinskia at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: giovannibajo at libero dot it @ 2004-05-13 13:34 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From giovannibajo at libero dot it 2004-05-13 02:11 -------
Wolfgang is right, and before anybody asks, no, there is no way to define a of
a specialized member variable without giving it an initializer, because the
syntax clashes with the specialization declaration, and it is always resolved
as the latter.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15394
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/15394] g++ fails to produce a static definition for static template member
2004-05-13 1:00 [Bug c++/15394] New: g++ fails to produce a static definition for static template member razeh at yahoo dot com
` (2 preceding siblings ...)
2004-05-13 13:34 ` giovannibajo at libero dot it
@ 2005-06-26 14:55 ` pinskia at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-06-26 14:55 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-06-26 14:55 -------
*** Bug 22191 has been marked as a duplicate of this bug. ***
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |bin-krzysiek at poczta dot
| |gazeta dot pl
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15394
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-06-26 14:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-13 1:00 [Bug c++/15394] New: g++ fails to produce a static definition for static template member razeh at yahoo dot com
2004-05-13 1:30 ` [Bug c++/15394] " pinskia at gcc dot gnu dot org
2004-05-13 1:42 ` bangerth at dealii dot org
2004-05-13 13:34 ` giovannibajo at libero dot it
2005-06-26 14:55 ` pinskia at gcc dot gnu dot org
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).