This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/10307: constructor for static object of template omitted
- From: bangerth at dealii dot org
- To: gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, kilpatds at oppositelock dot org, nobody at gcc dot gnu dot org
- Date: 3 Apr 2003 22:23:55 -0000
- Subject: Re: c++/10307: constructor for static object of template omitted
- Reply-to: bangerth at dealii dot org, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, kilpatds at oppositelock dot org, nobody at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
Synopsis: constructor for static object of template omitted
State-Changed-From-To: open->analyzed
State-Changed-By: bangerth
State-Changed-When: Thu Apr 3 22:23:54 2003
State-Changed-Why:
Behavior confirmed with all versions of gcc (2.95 .. 3.4).
Another testcase is this:
----------------------
#include <iostream>
// ------------- template
int template_counter = 0;
struct TemplateStatic {
TemplateStatic () { ++template_counter; }
};
template <typename T> struct Template {
static TemplateStatic s;
};
template <typename T> TemplateStatic Template<T>::s;
// ------------ non-template
int non_template_counter = 0;
struct NonTemplateStatic {
NonTemplateStatic () { ++non_template_counter; }
};
struct NonTemplate {
static NonTemplateStatic s;
};
NonTemplateStatic NonTemplate::s;
// ------------- use both
int main() {
Template<int> t;
NonTemplate nt;
std::cout << template_counter << " "
<< non_template_counter << std::endl;
}
---------------------------
Both Template and NonTemplate have a static variable,
but the constructor of them is only run for the non-template.
I think this is actually what the standard prescribes,
since static variables are only instantiated by use or
by explicit instantiation, not by instantiation of
the class they belong to. In fact, you can make the above
code work as you expect it by adding this line:
template TemplateStatic Template<int>::s;
Maybe someone of those with more knowledge of these matters
can confirm my interpretation?
Regards
Wolfgang
PS: icc7 agrees with gcc in all this, so I'd say it's not
a bug.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10307