https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98995

Jan Kokemüller <jan.kokemueller at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jan.kokemueller at gmail dot 
com

--- Comment #13 from Jan Kokemüller <jan.kokemueller at gmail dot com> ---
Sometimes, all of the padding bytes of a "[[no_unique_address]]" member are
known when designing a class. It would be great if there was a way to say:
"hey, it's OK to do guaranteed copy elision here". Example:

union U {
  [[no_unique_address]] Val val;
  [[no_unique_address]] Err err;
};

struct R {
  [[no_unique_address]] U union;
  [[no_unique_address]] bool has_val;
};

struct expected {
  R r;
};

In this example, "union U" and "struct R" are only used in the "struct
expected", by design. So it should be safe to allow guaranteed copy elision
when initializing the members "val" and "err" of the union since we have full
control over the tail padding bytes (there can only be "has_val" in there,
nothing else).

Maybe there could be an attribute, something like
"[[gnu::allow_guaranteed_copy_elision]]" or
"[[gnu::defer_temporary_materialization]]", to mark those members where
guaranteed copy elision is safe? So you could have:

union U {
  [[no_unique_address,gnu::defer_temporary_materialization]] Val val;
  [[no_unique_address,gnu::defer_temporary_materialization]] Err err;
};

What do you think?

Reply via email to