On 5/30/23 16:51, Jakub Jelinek wrote:
On Tue, May 30, 2023 at 04:36:34PM -0400, Jason Merrill wrote:
Note that it is fine to treat p->fld as invariant in C++ if fld is
TREE_READONLY and p is itself invariant.  The implementation is allowed to
assume that other code didn't destroy *p and create a new object with a
different value of p in the same location under
https://eel.is/c++draft/basic.memobj#basic.life-8.3

You mean
#include <cstdlib>
struct S { const int fld; S (int x) : fld (x) {} };
int foo (S *p)
{
   int a[p->fld];
   delete p;
   return sizeof (a);
}
is invalid (sure, VLA is an extension)?

Good point, no, I would expect that to work, since the user didn't actually write p->fld again.

Jason

Reply via email to