This is the mail archive of the gcc-bugs@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: c/4967: GCC should warn about obvious violations of restrict

[Get raw message]
On Thu, 29 Nov 2001, Andreas Jaeger wrote:

> The compiler should use the restrict keyword of ISO C99 when invoking
> functions and check that the aliasing rules are not violated on the
> call side.

Why?  The keyword provides no information whatsoever to the call side,
since the function needn't access the objects pointed to by its arguments
at all.

> Compile this program - it should give a warning:
> int
> sprintf_restrict (char *restrict s, const char *restrict t)
> {
>   return *s!=*t;
> }
> 
> 
> 
> int main (void)
> {
>   char buf[64];
> 
>   sprintf_restrict (buf, buf);
> 
>   return 0;
> }

The program is perfectly valid; while sprintf_restrict could have a const
on the target type of its first parameter, there's no need for it to have
one.

-- 
Joseph S. Myers
jsm28@cam.ac.uk


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