Just noticed that GCC appears to ignore top-level qualifiers on function return 
type when determining type compatibility. 

C's function type compatibility rules (the last paragraph of "6.7.7.4 Function 
declarators") require exact match between function return types, including 
their 
top-level qualifiers. For parameter types top-level qualifiers are ignored, but 
not for the return type. 

This implies that the function pointer initialization in the following code is 
supposed to be invalid

  const int foo(int a) { return 0; }
  
  int main(void) {
    int (*p)(int) = &foo;
  }

And indeed, Clang reports this with

  error: incompatible function pointer types initializing 'int (*)(int)' with 
    an expression of type 'const int (*)(int)'

Meanwhile, GCC is completely silent about it even in `-pedantic` mode.

Not a big deal, I guess, since top-level qualifiers on function return types 
are generally considered "pointless", but still, a diagnostic is required for 
the above example.

-- 
Best regards,
Andrey

Reply via email to