On 8/29/23 09:35, Nathaniel Shead wrote:
This is an attempt to improve the constexpr machinery's handling of
union lifetime by catching more cases that cause UB. Is this approach
OK?
I'd also like some feedback on a couple of pain points with this
implementation; in particular, is there a good way to detect if a type
has a non-deleted trivial constructor? I've used 'is_trivially_xible' in
this patch, but that also checks for a trivial destructor which by my
reading of [class.union.general]p5 is possibly incorrect. Checking for a
trivial default constructor doesn't seem too hard but I couldn't find a
good way of checking if that constructor is deleted.
I guess the simplest would be
(TYPE_HAS_TRIVIAL_DFLT (t) && locate_ctor (t))
because locate_ctor returns null for a deleted default ctor. It would
be good to make this a separate predicate.
I'm also generally unsatisfied with the additional complexity with the
third 'refs' argument in 'cxx_eval_store_expression' being pushed and
popped; would it be better to replace this with a vector of some
specific structure type for the data that needs to be passed on?
Perhaps, but what you have here is fine. Another possibility would be
to just have a vec of the refs and extract the index from the ref later
as needed.
Jason