C ++ language standard speaks in D.5
2 Each C header, each of which has a name of the form name.h , behaves as if each name was placed in the standard library namespace; the corresponding cname header is placed in the global namespace volume. It is not indicated whether these names are first declared or defined in the namespace (3.3.6) of the std and then explicitly used-declarations (7.3.3) are entered into the global namespace realm.
3 [Example: the <cstdlib> header undoubtedly provides its declarations and definitions within the std . It can also provide these names in the global namespace. The <stdlib.h> header undoubtedly provides the same declarations and definitions in the global namespace as in Standard C. It can also provide these names in the std . -end example]
This is apparently quite explicit ("... every name ...", "... the same declarations ...") that the old-style <name.h> headers should provide the same set of declarations as and the <cname> headers of the new style, but in the global namespace. An exception for C ++ - specific overloaded versions of various C-functions, for example, is not made.
This means that <math.h> should provide three versions of the sin function: sin(float) , sin(double) and sin(long double) in the global namespace. This, in turn, means that the following C ++ code must have overload permission
#include <math.h> int main() { sin(1); }
It crashes with the MSVC ++ compiler, but it compiles successfully in GCC and Clang. So, does GCC just ignore the standard requirement for legacy old-style headers? Or did I somehow misinterpret the wording in the standard?
source share