I am attempting to compile/link my file named test.cpp from the command line using VS2017 on a 64-bit Win10 system. I use these two commands:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cl test.cpp
and I get the following results:
C:\temp\tests>"C:\Program Files (x86)\Microsoft Visual
Studio\2017\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.4.5
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
C:\temp\tests>cl test.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.11.25547 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
test.cpp
test.cpp(2): error C2365: 'y1': redefinition; previous definition was 'function'
C:\Program Files (x86)\Windows
Kits\10\include\10.0.16299.0\ucrt\corecrt_math.h(984): note: see declaration of 'y1'
test.cpp(5): error C2659: '=': function as left operand
My file contains the following code:
#include <new>
static int *y1;
int main()
{
y1 = new (std::nothrow) int;
}
While I understand why this is happening and any number of kluges that will fix it, it seems to me that the actual defect is in the Microsoft corecrt_math.h header file. When I look there I see several more identifiers (j0, jn, jn, etc.) that could just as easily be legitimately chosen by an unsuspecting programmer, only to end up with the same problem. I was under the impression that there was a "gentlemen's agreement" that exposed undocumented identifiers in library code would start or end with an underbar and user code would not, just to avoid this type of problem.
<cmath>
, not via<math.h>
. Of course, considering history, that was not such a realistic requirement, it was IMHO stupid. OH. Microsoft introduced some of these with simpler names at least back in VS 2015. Still from the docs it looks like they have leading underscore?y1
is also a POSIX.1-2001 function specified to be in<math.h>
. But it's interesting it would end up indirectly included from<new>
.