On 9/9/07, Mark Mitchell <[EMAIL PROTECTED]> wrote: > Richard Guenther wrote: > > > I don't know of any place we would use such information. At least > > > > int *p = new int; > > int *q = new int; > > if (p == q) > > > > cannot be simplified as both pointers may be NULL? > > They cannot be NULL; new-expressions throw an exception if the > allocation fails. (Of course, they could be NULL if you called the > "nothrow" variant, or another "operator new" declared "throw()".) > > We should optimize away things like: > > int *p = new int; > if (!p) > cerr << "Could not allocate memory\n";
We don't I believe. We'd optimize int *p = new int; *p; if (!p) cerr << "Could not allocate memory\n"; though ;) Well, at least malloc is allowed to return NULL, so unless we want to force all malloc attributed functions in C++ to throw exceptions we cannot assume they return non-NULL (just on the basis they have malloc attribute, that is). Richard.