public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: bangerth@dealii.org
To: gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org,
	kilpatds@oppositelock.org, nobody@gcc.gnu.org
Subject: Re: c++/10307: constructor for static object of template omitted
Date: Thu, 03 Apr 2003 22:23:00 -0000	[thread overview]
Message-ID: <20030403222355.15101.qmail@sources.redhat.com> (raw)

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


             reply	other threads:[~2003-04-03 22:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-03 22:23 bangerth [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-04-07 14:20 bangerth
2003-04-04 20:26 Wolfgang Bangerth
2003-04-04 20:16 Wolfgang Bangerth
2003-04-03 21:46 kilpatds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030403222355.15101.qmail@sources.redhat.com \
    --to=bangerth@dealii.org \
    --cc=gcc-bugs@gcc.gnu.org \
    --cc=gcc-gnats@gcc.gnu.org \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=kilpatds@oppositelock.org \
    --cc=nobody@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).