This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++: constant folding in a conditional expr
Nathan Sidwell writes:
> Andrew Haley wrote:
> > This test case fails if BROKEN is #defined:
> This test case is illformed, regardless of BROKEN's #definedness :-)
>
> [9.4.2]/4 requires an out of class definition of static data members
> yea, even if the in-class declaration is of a constant type and
> contains an initializer.
Right. I see
"If a static data member is of const integral or const enumeration
type, its declaration in the class definition can specify a
constant-initializer which sahll be an integral constant expression.
In that case, a member can appear in integral constant expressions
within its scope."
So, what would the legal form of this program be? Like this, I guess:
class Foo
{
public:
static const unsigned ACONST = 0;
static const unsigned BCONST = 1;
void SetData(bool p);
private:
unsigned _data;
};
const unsigned Foo::ACONST;
const unsigned Foo::BCONST;
> > I've written a patch that doesn't treat the conditional expr as an
> > lvalue if either arm is read only, and that seems to fix the problem,
> > but is it the right fix?
> I don't think so. What if I wrote
> ptr = &(data ? ACONST : BCONST);
Ah. :-)
Thanks very much,
Andrew.