On Sat, Nov 12, 2005 at 04:01:07PM -0500, Andrew Pinski wrote: > Was there an example of: > > int f(int &); > > int g(void) > { > int *a = 0; > return f(*a); > } > > > Yes this would be undefined code but so what.
In a case like this, gcc could emit an error (since we can already detect that a reference is always initialized to a null pointer). If it did so, I can almost guarantee that some free software package will be flagged (I recall writing such code myself 10+ years ago, before I knew better), but it still might be a good thing. Of course, it's not hard to hide the fact that a reference is null from the compiler, and the compiler might then do optimizations based on the assumption that the argument to f is a non-null reference. That would be valid according to the standard.