On Wed, Mar 16, 2011 at 10:02 PM, Jason Merrill <[email protected]> wrote: > On 03/16/2011 10:43 PM, Gabriel Dos Reis wrote: >> >> The real problem is that the data member of the object is not initialized. >> Fully constructed subobjects in constexpr constructor are still >> be potential constant expressions. >> For example, we should not reject >> >> struct S { >> int i; >> int j; >> constexpr S(int a) : i(a), j(i*i) { } >> }; > > I thought about that, but it seems to me that the implementation complexity > for supporting that usage would be much higher than it is worth. Nowhere > else in constant expression evaluation do we have to deal with assigning a > value at one point and then getting it back later.
A base class subobject of a literal class has similar property. I am not sure we need more infrastructure or more complexity in the implementation. The (C++98) language already requires us to initialize subobjects in their order of declaration. That is what we do here. All we need is to check that a member, whose value is being used in the initialization of another member (which might be itself like in this PR) is initialized. When we look up `this' in the evaluation environment, we can tell whether a particular slot has been initialized. -- Gaby
