Apparent aliasing problem when optimizing

Marc Singer elf@buici.com
Thu Apr 10 17:27:00 GMT 2003


Thanks for the clarification.  I look forward to seeing the new
warning or error.

> > I read your explanation.  Why (void*) cannot be a reference type
> > when (IShellFolder*) is?
> 
> Neither of them is a reference type.  You can take the address of a
> *variable* of any type, but you cannot take the address of a *cast*.

A reader of an email list suggested this form 

  &(void*&)psf

which appears to work correctly when optimized.  

I hope you appreciate the fact that the unoptimized code works
correctly with my original syntax.  It's the optimizer that gets
confused and decides to ignore the fact that the value may have
changed.  I understand how it is that this form is not allowed.  Yet,
I don't really see why the restriction is necessary.

I've sometimes done this, which the 3.2.3 compiler accepts.

  void* pv = (void*) 2;
  char* pc = (char*) 1;
  (void*) pc = pv;
  printf ("? %p %p\n", pv, pc);

IMHO, it seems arbitrary that one cannot take the address of a casted
value when the cast, in these cases, is purely syntactical.  There are
times when casting the target is simpler than casting the source.



More information about the Gcc-bugs mailing list