Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Temporaries have static storage duration?

1 view
Skip to first unread message

Johannes Schaub (litb)

unread,
Oct 16, 2009, 12:15:38 AM10/16/09
to
I wonder about 3.7.1[basic.stc.static]/1:

All objects which do not have dynamic storage duration, do not have thread
storage duration, and are not local have static storage duration. The
storage for these objects shall last for the duration of the program.

I always thought their storage duration is unspecified. Is the following
program valid, as a consequence of the above?

struct A {
int storage;
int *addy() { return &storage; }
};

int *get() { return A().addy(); }

int main() {
*get() = 42;
}

Notice that i'm not asking about its lifetime. I know that A() is destroyed
when the function returns. But since its storage is said to persist, we
should be able to reuse it, should we? Or is "A()" a "local object"? What
makes an object local? Thanks for all your insight.

--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std...@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]

tohava

unread,
Oct 18, 2009, 10:53:51 AM10/18/09
to
> I wonder about 3.7.1[basic.stc.static]/1:
>
> All objects which do not have dynamic storage duration, do not have thread
> storage duration, and are not local have static storage duration. The
> storage for these objects shall last for the duration of the program.

Aren't temporaries considered local in that respect?

Johannes Schaub (litb)

unread,
Oct 18, 2009, 5:35:25 PM10/18/09
to
tohava wrote:

>> I wonder about 3.7.1[basic.stc.static]/1:
>>
>> All objects which do not have dynamic storage duration, do not have
>> thread storage duration, and are not local have static storage duration.
>> The storage for these objects shall last for the duration of the program.
>
> Aren't temporaries considered local in that respect?
>

Temporaries are without a name, so they can't be inherited a scope. Even
though the Standard never defines the term "local object" (and there are
defect reports about that), i've always felt it means "an object defined by
a local name".

But now, of course if that's its meaning, this would have the consequence of
giving temporaries (except exception objects, i guess, which have been given
explicit license of having unspecified memory) static storage duration.

0 new messages