This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Quick sanity check



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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]