This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: g++ static data members [solaris27 + gcc-2.95.2/egcs]
- To: bkoz at cygnus dot com, gcc-bugs at gcc dot gnu dot org, mark at codesourcery dot com
- Subject: Re: g++ static data members [solaris27 + gcc-2.95.2/egcs]
- From: Mike Stump <mrs at windriver dot com>
- Date: Mon, 6 Mar 2000 15:49:05 -0800 (PST)
> Date: Mon, 6 Mar 2000 10:29:40 -0800
> To: gcc-bugs@gcc.gnu.org, bkoz@cygnus.com
> From: Benjamin Kosnik <bkoz@cygnus.com>
> I believe this problem has to do with cc1plus not putting the data
> into the correct section: here are two snippets from example code
> included below.
Well, if you had filed a complete bug report, it would be easier for
those that can help you to help you. I came very close to not being
able to help you because of this. I'd love to help you, as I would
love to see the new library code put into gcc. I recommend that all
future bug reports include at least the testcase. (g++ -E). Luckily
I found a 2.7 machine lying around here to try it one.
> It's clear to me that _S_table should be in .data, not .bss.
That's fine, but wrong:
3.6.2 Initialization of non-local objects [basic.start.init]
1 The storage for objects with static storage duration (3.7.1) shall be
zero-initialized (8.5) before any other initialization takes place.
Objects of POD types (3.9) with static storage duration initialized
with constant expressions (5.19) shall be initialized before any
dynamic initialization takes place. Objects of namespace scope with
static storage duration defined in the same translation unit and
dynamically initialized shall be initialized in the order in which
their definition appears in the translation unit. [Note: 8.5.1
describes the order in which aggregate members are initialized. The
initialization of local static objects is described in 6.7. ]
We are allowed to generate this type of code if we want to. Do you
mean to critique our code generation strategy, or are you just being
confused by it, I can't tell. My guess is that you are being confused
by it. You cannot rely upon (in C++) it being initialized until the
dymanic point in program start up is hit: Welcome to C++.
> Any thoughts? I've been unable to compile CVS egcs/gcc on
> solaris2.7, so anybody with a current g++ binary care to run the
> code below through it, and see what section _S_table is in?
It is run time initialized. Some changes by Mark seem to have caused
it.(?) It used to not be run time initialized. I don't know why Mark
wanted to defer it. Maybe that was an accident? If so, I think it
should be moved back to static time initialization. The change that I
was guessing is related was:
1999-09-30 Mark Mitchell <mark@codesourcery.com>
> Is there a patch to put data like this into .data and not .bss on
> solaris2.7?
Below is a testcase for the problem:
extern unsigned int *__ctype_mask;
typedef unsigned int size_t;
struct ctype_base {
typedef unsigned int mask;
};
template<typename _CharT>
class ctype : public ctype_base
{ };
template<>
class ctype<char> : public ctype_base
{
typedef char char_type;
private:
const mask* _M_table;
bool _M_del;
static const mask* const& _S_table;
public:
explicit
ctype(const mask* __table = 0, bool __del = false,
size_t __refs = 0) throw()
: _M_table(__table == 0 ? _S_table: __table),
_M_del(__table != 0 && __del) { }
};
const ctype_base::mask* const& ctype<char>::_S_table = __ctype_mask ;