How to workaround on this (bug?)

H. S. Teoh hsteoh at qfbox.info
Sat Sep 17 00:28:44 UTC 2022


On Sat, Sep 17, 2022 at 12:19:16AM +0000, frame via Digitalmars-d-learn wrote:
> On Friday, 16 September 2022 at 23:06:35 UTC, H. S. Teoh wrote:
> 
> > Basically, if you pass something to .fun by value, then that value
> > must be destroyed by .fun once it's ready to return.  So if the
> > value has a dtor, the dtor must be called upon exiting from .fun.
> > Since Variant has a throwing dtor, this means .fun may throw when
> > it's about to return, which violates `nothrow`.
> 
> I understand why this happens but not why the compiler does not check
> if the value is actually destroyed in user code by `.destroy()`.
[...]

I don't know for sure, but my guess is that .destroy is seen by the
compiler just like any other D function; i.e., it's not treated
specially. So it would not factor into the compiler's lifetime
considerations.

Or are you talking about the case where the Variant may not actually
contain values that have dtors?  That information is not available until
runtime; the compiler can't make decisions based on that.


T

-- 
Political correctness: socially-sanctioned hypocrisy.


More information about the Digitalmars-d-learn mailing list