Search code examples
cc99c11restrictrestrict-qualifier

Parameters declared restrict and compiler warnings


Neither gcc 5 nor clang 3.6 give warnings where the constraints of the restrict qualifier are violated, even when called with -Wall. Consider the following code fragment:

extern void f(char *restrict p, char *restrict q);

void g(char *p)
{
    f(p, p);
}

Naively, I'd expect that the violation can be determined statically, and I was expecting that -Wall would give a warning. Have I missed a flag somewhere, or is there some problem with giving warnings that I'm not seeing?


Solution

  • Starting with version 8, gcc gives a helpful warning for the above code:

    a.c: In function ‘g’:
    a.c:5:5: warning: passing argument 1 to restrict-qualified parameter aliases with argument 2 [-Wrestrict]
         f(p, p);
         ^