This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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: Bugs/non-portable assumptions in libstdc++


On Fri, 19 Nov 2004, Paolo Carlini wrote:
> Hi Chris,

Hi Paolo, Nathan, and Benjamin,

Sorry for the delay.

> >With this as background, I have two questions for the list: 1. Do you
> >agree that this is really a bug/non-portable assumption?
> Well, 3.6.2/1:
>
>     "Objects with static storage duration (3.7.1) shall be zero
> inizialized (8.5) before
>     any other inizialization takes place."

> Or I'm missing something/you actually mean something else?!?

I'm sorry I wasn't clear.  In particular, I specifically mean non-POD
objects.  The reference above seems to really to only apply to POD objects
that don't have constructors.

In particular, 12.6.2.4 (in 14882-2003b) says:

"...
After the call to a constructor for class X has completed, if a member of
X is neither specified in the constructors mem-initializers, nor
default-initialized, nor value-initialized, nor given a value during
execution of the body of the constructor, the member has indeterminate
value."

>From my understanding of this passage, an implementation that dynamically
memset the memory for an object to all ones (for example) before it ran
the constructor of an object would be fully conformant.  The fact that the
object has static storage duration has no effect on the fact that the
member is not being initialized, in any of the above specified places, so
it has indeterminate value.

As a concrete example, I think this assertion should be allowed to fail,
though (of course) it is unlikely to for most implementations:

----
#include <cassert>
struct X { int Y; X() {} };
X G;
int main() { assert(G.Y == 0); }
----

Does this clarify what I mean?  In particular, I'm far from being a
language lawyer, so it's likely I'm missing something.  In particular
though, I am only discussing non-POD types that have constructors.

Thanks for the feedback,

-Chris

>
> >  2. Do you know
> >of any other places in libstdc++ where this 'optimization' (eliding the
> >initialization) is done?
> >
> >
> Yes, for sure _S_empty_rep_storage in basic_string, most likely others...
>
> Thanks,
> Paolo.
>

-Chris

-- 
http://llvm.org/
http://nondot.org/sabre/


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