This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Quick sanity check
- From: Denis Nagorny <denis_nagorny at linux dot intel dot com>
- To: Perry Smith <pedz at easesoftware dot net>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 20 Feb 2006 09:51:23 +0300
- Subject: Re: Quick sanity check
- References: <43C67E4B-6B75-47AB-80B5-590F3F0ACD57@easesoftware.net>
You'd be guided by 9.2 p4:
"A member-declarator can contain a constant-initializer only if it declares a static member (9.4)
of integral or enumeration type, see 9.4.2."
As &sge::flags isn't integral type (It's pointer-to-member) you need take initializer out of class declaration.
class sge
{
public:
uint64_t address;
uint32_t count;
uint32_t flags;
};
class bitfield
{
public:
const uint32_t sge::*field;// = &sge::flags;
// ^^^^^^^^^^^^^^^^^
static const uint32_t bit_start = 31;
static const uint32_t bit_stop = 31;
};
const uint32_t sge::*field = &sge::flags;
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
class sge {
public:
uint64_t address;
uint32_t count;
uint32_t flags;
};
class bitfield {
public:
const uint32_t sge::*field = &sge::flags;
static const uint32_t bit_start = 31;
static const uint32_t bit_stop = 31;
};
g++ -o foo foo.C && ./foo
foo.C:14: error: 'sge::flags' cannot appear in a constant-expression
foo.C:14: error: `&' cannot appear in a constant-expression
foo.C:14: error: ISO C++ forbids initialization of member 'field'
foo.C:14: error: making 'field' static
foo.C:14: error: invalid in-class initialization of static data member
of non-integral type 'const uint32_t sge::*'
Thank you,
Perry