This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] Marking C++ new operator as malloc?


Richard Guenther wrote:
> On 9/9/07, Mark Mitchell <mark@codesourcery.com> wrote:
>> But, I don't think that even the C meaning is safe in C++ for use with
>> the library declaration of <new>.  I'm also somewhat skeptical of the
>> idea that we will never do any optimization on pointer comparisons.
>> What design principle in the compiler is going to keep us from some day
>> introducing the obvious idea that "if modifying *p cannot affect the
>> value of *q, and p and q are of the same type, then p != q"?
> 
> But that reasoning is not valid.  Consider
> 
>  void foo(int *q, double *p)
>  {
>     if (q != p)
>       abort ();
>  }
>  int main()
>  {
>    int i;
>    foo (&i, &i);
>  }

That doesn't type-check; did you want to have a cast somewhere?  Note
that my statement above depends on the pointers having the same type.

What is an example program in that meets the requirements I gave above
-- i.e., allows the compiler to prove that two same-typed pointers do
not alias (whether by the compiler's cleverness, use of "restrict", or
whatever), but where the compiler must still assume that the values of
the pointers might be the same?

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]