Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[except.ctor] stack unwinding vs. automatic storage duration #4548

Closed
xmh0511 opened this issue Mar 17, 2021 · 4 comments · Fixed by #4550
Closed

[except.ctor] stack unwinding vs. automatic storage duration #4548

xmh0511 opened this issue Mar 17, 2021 · 4 comments · Fixed by #4550
Assignees

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Mar 17, 2021

In section [except.ctor], the rule states:

  1. As control passes from the point where an exception is thrown to a handler, objects with automatic storage duration are destroyed by a process, specified in this subclause, called stack unwinding.
  1. If the initialization or destruction of an object other than by delegating constructor is terminated by an exception, the destructor is invoked for each of the object's direct subobjects and, for a complete object, virtual base class subobjects, whose initialization has completed ([dcl.init]) and whose destructor has not yet begun execution, except that in the case of destruction, the variant members of a union-like class are not destroyed. [ Note: If such an object has a reference member that extends the lifetime of a temporary object, this ends the lifetime of the reference member, so the lifetime of the temporary object is effectively not extended. — end note ] The subobjects are destroyed in the reverse order of the completion of their construction. Such destruction is sequenced before entering a handler of the function-try-block of the constructor or destructor, if any.

That means what the third rule says is also a part process of stack unwinding.

Since the first rule sounds like that the invocation of stack unwinding is only for the object with automatic storage duration. Doesn't that stack unwinding invoke for the object with dynamic storage duration or others duration?

struct A{
  ~A(){
    
  }
};
struct B{
 B(){
   throw 0;
 }
  A a;
};
int main(){
   try{  
      auto ptr = new B{};
    }catch(int){
   }
}

Obviously, the subobject a occupies the storage within the complete object of the type B which has the dynamic storage duration. AFAIK, A's destructor should be invoked since it has been completely constructed in the initialization of B.

@jensmaurer
Copy link
Member

I think we can just strike "with automatic storage duration"; this is an intro sentence that doesn't really say much normatively. The detailed specification is in the following paragraphs.

@jensmaurer jensmaurer changed the title An issue about the description of stack unwinding [except.ctor] stack unwinding vs. automatic storage duration Mar 18, 2021
@xmh0511
Copy link
Contributor Author

xmh0511 commented Mar 19, 2021

I think we can just strike "with automatic storage duration"; this is an intro sentence that doesn't really say much normatively. The detailed specification is in the following paragraphs.

Since CWG 1774 was approved that destruction of subjects should be also considered as stack unwinding, the introduction of stack unwinding through associating with objects that have automatic storage duration is a bit of contradiction.

@jensmaurer
Copy link
Member

jensmaurer commented Mar 19, 2021

I think we're in violent agreement here.

CWG1774 cleaned up the entire section.

The "with automatic storage duration" was re-introduced (out of nowhere) by commit f3a6b2e for CWG2256, ignorant of the careful redrafting that was done by CWG1774 (which stroke "with automatic storage duration" from that intro sentence).

@tkoeppe, @zygoloid: I'd like to editorially strike "with automatic storage duration" from the intro sentence, because it's wrong in the case of throwing from the constructor of a partially-constructed object, where subobjects might have dynamic storage duration. Any objections?

@tkoeppe
Copy link
Contributor

tkoeppe commented Apr 30, 2021

OK, I trust your judgement on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants