Are there any unintuitive side effects of member subobjects that inherit storage duration?

I did not know this before, but it turns out that:

[C++11: 3.7.5]: The storage duration of member subobjects, base class subobjects and array elements is their complete object (1.8).

This means that x->a in the example below has a dynamic storage duration.

I am wondering if there is any other specific semantics that refers to the storage duration that inherits member a with a different behavior between the *x and y object? An example is the rule that determines the lifespan of an object.

 struct T { int a; }; int main() { std::unique_ptr<T> x(new T); T y; } 

And what about if T were non-PODs (and other types of UDTs)?

In short, my lizard brain expects any declaration similar to int a; will have an automatic (or static) storage duration, and I wonder if this accidentally calls the standard wording.


Update:

Here is an example:

[C++11: 3.7.4.3/4]: [..] Alternatively, the implementation may have strict pointer safety, in which case a pointer value that is not a safe pointer value is an invalid pointer value , unless the reference is a complete object does not have dynamic storage duration [..]

On its surface, I would not expect the semantics to differ between my x->a and my ya , but it is clear that there are areas that are clearly not related to the lifetime of the object when they do it.

I am also concerned about lambda capture rules that explicitly indicate "with automatic storage duration" in several places, for example:

[C++11: 5.1.2/11]: If a lambda expression has a capture-default and its compound operator odr-uses (3.2) this or a variable with automatic storage duration [..]

[C++11: 5.1.2/18]: Each occurrence of decltype((x)) , where x is perhaps an id expression in parentheses that names an object with automatic storage duration , as if x was converted to access to the corresponding data element of the closure type, which would be declared if x was an odd use of the indicated object.

and others.

+7
source share
1 answer

Not. This inheritance of storage duration is what subobjects do. To do anything else would simply be completely impossible. In addition, you cannot create any types that could be distributed either statically or dynamically.

Simply put, any violation of this rule will simply break everything.

+2
source

All Articles