Simple question: shall a #pragma
leading to nonstandard behavior cause __STDC__
macro not to be defined to 1? (Does the C standard explicitly prescribes that? If yes, then in which section? If no, then why?) Reason of the question: see below.
Sample code (t28.c):
#pragma warning( disable : 34 )
typedef int T[];
int main()
{
int rc = sizeof(T);
#if __STDC__ == 1
rc = 0;
#else
rc = 1;
#endif
return rc;
}
Invocation: cl t28.c /std:c11 /Za && t28 ; echo $?
Expected result: 1
Actual result: 0
Compiler version:
cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29913 for x64
Note: C11 (6.5.3.4 The sizeof and _Alignof operators) (emphasis added):
The sizeof operator shall not be applied to an expression that has function type or an incomplete type, ...
Here we see that #pragma
leads to nonstandard behavior: "shall requirement" is violated, diagnostic message is not generated, compiler's backend is called, .exe
is produced and successfully executed. However, this nonstandard behavior does not cause __STDC__
macro not to be defined to 1
.
Reason of the question: tests. One test, similar to t28.c
is failing because it expects return code 1
(__STDC__
is not defined to 1
). Which part of the system contains the bug: test or compiler (or both)?