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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
private isn't needed.
struct S {
  S () = default;
  constexpr S (const S &) noexcept : s{this} {}
  constexpr S & operator= (const S &) noexcept { return *this; }
  constexpr bool foo () const noexcept { return s == this; }
  S *s = this;
};

constexpr bool
bar (S x) noexcept
{
  return x.foo ();
}

static_assert (bar (S {}), "");
static_assert ([] (S x) { return x.foo (); } (S {}), "");

The most important change in that commit was to make a copy of the inline body
before it is destructively changed during genericization.  On the other side,
one of the important changes genericization does is adjust accesses to
DECL_BY_REFERENCE PARM_DECLs/RESULT_DECLs.
During the evaluation of static assert, I see we are first evaluating
bar (&TARGET_EXPR <D.2583, <<< Unknown tree: aggr_init_expr
  4
  __ct_comp 
  D.2583
  (struct S *) <<< Unknown tree: void_cst >>> >>>>);
which means that expression is adjusted for the passing of invisiref parms, we
are
passing there address of D.2583 variable with S type which is constructed.
But, later on when trying to constexpr evaluate the body of bar, we see
S::foo (&x);
call, so passing address of x to the method, where x is PARM_DECL with S type.
DECL_BY_REFERENCE even isn't set (yet) on it.
I guess we need to somewhere during constexpr evaluation take into account that
S pointer/reference has been passed to the function (to an invisiref parm) and
the function body still uses it directly rather than changing it into a
pointer/reference and dereferencing it.

Reply via email to