Search code examples
c++functionsizeof

sizeof over a function type; gcc doesn't recognized it as ill-formed


Doing this little test (http://coliru.stacked-crooked.com/a/71096660a727f4b0):

#include <iostream>

int main()
{
   std::cout << sizeof(void()) << '\n';
}

gcc yields a warning instead of an error (and prints 1). Shouldn't that be treated as an ill-formed expression as clang does?


Solution

  • The standard doesn't discriminate between a warning and error. So, an ill-formed construct can have a warning emitted only. It is not a requirement that compilation should fail also. The only requirement is that diagnostics should be issued. The exact meaning of diagnostics is not specified.

    (And a related note: there are some constructs, which are ill-formed, but no diagnostics required at all by the standard)