rjmccall added a comment.

In https://reviews.llvm.org/D44536#1054929, @rsmith wrote:

> It seems that we have two options: either we valiantly try to support this:
>
> - we keep a list of types for which we've tried to form a 
> //delete-expression//, but found that the type was incomplete
> - when such a type is completed, we mark the destructor as used, triggering 
> its synthesis or instantiation if necessary, and likewise for the `operator 
> delete`
> - we change our `CXXDeleteExpr` representation so that we don't store any 
> information that might be changed by completing the class on the expression, 
> such as the selected `OperatorDelete` function and whether we're performing a 
> sized delete


Yeah, this is probably unworkable.  (Of course I'm brainstorming ways we could 
do it — we could have a global entry for late-realized destructor information.  
But it just seems like a terrible idea.)

> ... or we say that we're not interested in calling the destructor for code 
> like this that has undefined behavior. The latter is certainly my preference; 
> it seems hard to justify the complexity required to get this "right", 
> especially since we still won't get it right in cases where we choose to emit 
> some function definitions before the end of the TU.

I agree.

> I agree with John that tracking that we're in the "delete of incomplete class 
> type" case (or some equivalent state, such as a "need to run a cleanup" flag) 
> on the `CXXDeleteExpr` seems best. We should be careful to ensure that we 
> rebuild the expression in template instantiation when the "delete of 
> incomplete class type" flag is set, even if the expression is non-dependent, 
> though. That is, I think this should work:
> 
>   struct X { ~X(); };
>   struct A;
>   A *get();
>   template<int> void f() { delete (&get)(); }
>   struct A { X x; };
>   A *get() { return new A; }
>   void g() { f<0>(); }
> 
> 
> ... even though we first form a (non-dependent) //delete-expression// for an 
> `A` at a point where `A` is incomplete.

Good point.  I agree that we should allow incomplete deletes to work as long as 
they've been completed by instantiation time.


Repository:
  rC Clang

https://reviews.llvm.org/D44536



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D44536: A... Richard Smith - zygoloid via Phabricator via cfe-commits
    • [PATCH] D445... Richard Smith - zygoloid via Phabricator via cfe-commits
    • [PATCH] D445... John McCall via Phabricator via cfe-commits

Reply via email to