c/4967: GCC should warn about obvious violations of restrict
Joseph S. Myers
jsm28@cam.ac.uk
Thu Nov 29 04:41:00 GMT 2001
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
More information about the Gcc-bugs
mailing list