From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15121 invoked by alias); 3 Apr 2003 22:23:55 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 15102 invoked by uid 48); 3 Apr 2003 22:23:55 -0000 Date: Thu, 03 Apr 2003 22:23:00 -0000 Message-ID: <20030403222355.15101.qmail@sources.redhat.com> To: gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, kilpatds@oppositelock.org, nobody@gcc.gnu.org From: bangerth@dealii.org Reply-To: bangerth@dealii.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, kilpatds@oppositelock.org, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org Subject: Re: c++/10307: constructor for static object of template omitted X-SW-Source: 2003-04/txt/msg00118.txt.bz2 List-Id: 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 // ------------- template int template_counter = 0; struct TemplateStatic { TemplateStatic () { ++template_counter; } }; template struct Template { static TemplateStatic s; }; template TemplateStatic Template::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 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::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