c++/10307: constructor for static object of template omitted
bangerth@dealii.org
bangerth@dealii.org
Thu Apr 3 22:23:00 GMT 2003
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
More information about the Gcc-bugs
mailing list