Standard library identifiers conflict with user identifiers - c++

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.

This build command works for me:
cl foo.cpp /Feb /D _CRT_DECLARE_NONSTDC_NAMES=0

Related

Strange issue with abs(complex) in Visual Studio C++ 2015 Update 3

After updating to Visual Studio 2015 Update 3 (from Visual Studio 2015), this code no longer compiles:
#include<cmath>
#include<complex>
int main()
{
std::complex<double> update(0.0, 0.0);
double x = std::abs(update);
return 1;
}
I am getting the following error when running the compiler:
c:\projects\foo\win64>cl /EHsc /fp:strict foo.cc
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24213.1 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
foo.cc
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xcomplex(232): er
ror C2131: expression did not evaluate to a constant
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xcomplex(232): no
te: failure was caused by an undefined arithmetic operation
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xcomplex(253): no
te: see reference to function template instantiation '_Ty std::_Fabs<double>(con
st std::complex<double> &,int *)' being compiled
with
[
_Ty=double
]
foo.cc(6): note: see reference to function template instantiation '_Ty std::abs<
double>(const std::complex<double> &)' being compiled
with
[
_Ty=double
]
This issue seems to be tied with my usage of fp:strict, which is necessary for proper IEEE floating point. Is this an issue with my code?
I test it in VS2013 with update 5 and VS2015 with update 3, it really has this issue in VS2015, but everything compiled normally in VS2013 with the same property settings /fp:strict. I help you submit a new feedback to the connect report here:
https://connect.microsoft.com/VisualStudio/feedbackdetail/view/3101450/c2131-expression-did-not-evaluate-to-a-constant-error-in-vs2015-update-3
Maybe the report team could provide better solution for this issue. You could vote it.

Visual Studio 2013 crashes for non-static data member initialization

i wanna compile Trinitycore with visual studio 2013(x86 & x64 both tested) on windows 10
i get this error and i test every solutions such as:
1.change /Zm on Additional Options from /Zm500 to /Zm2000(Maximum)
2.disable precompiled headers
3.disable Optimization
4.re-install Visual Studio
5.re-install windows 10
visual studio error description:
Error 1 error C1001: An internal error has occurred in the compiler. \TrinityCore-3.3.5\src\server\game\Server\WorldSocket.cpp 256 1 game
Error 2 error C1060: compiler is out of heap space c\src\server\game\c1xx game
Error 3 error D8040: error creating or communicating with child process c\src\server\game\cl game
event log:
Faulting application name: CL.exe, version: 18.0.21005.1, time stamp: 0x524faabf
Faulting module name: c1xx.dll, version: 18.0.21005.1, time stamp: 0x524faa90
Exception code: 0xc0000005
Fault offset: 0x0025236e
Faulting process id: 0x1948
Faulting application start time: 0x01d19f24d391755f
Faulting application path: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe
Faulting module path: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\c1xx.dll
Report Id: d98e09ae-0b18-11e6-b361-1008b14a12cc
Faulting package full name:
Faulting package-relative application ID:
vs output errors:
TrinityCore-3.3.5\src\server\game\Server\WorldSocket.cpp(256): fatal error C1001: An internal error has occurred in the compiler.
1> (compiler file 'f:\dd\vctools\compiler\cxxfe\sl\p1\c\convert.cpp', line 9608)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
1> Opcodes.cpp
1>c1xx : fatal error C1060: compiler is out of heap space
1> An internal error has occurred in the compiler.
1> (compiler file 'msc1.cpp', line 1325)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
1>cl : Command line error D8040: error creating or communicating with child process
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
event log attached file:
Version=1
EventType=APPCRASH
EventTime=131060826745545591
ReportType=2
Consent=1
UploadTime=131060826747020586
ReportIdentifier=e3cb3d99-0b13-11e6-b361-1008b14a12cc
IntegratorReportIdentifier=e3cb3d98-0b13-11e6-b361-1008b14a12cc
WOW64=1
Response.BucketId=d11da6a9b6e3e8a8c8d50161959694bb
Response.BucketTable=1
Response.LegacyBucketId=-389226431
Response.type=4
Sig[0].Name=Application Name
Sig[0].Value=CL.exe
Sig[1].Name=Application Version
Sig[1].Value=18.0.21005.1
Sig[2].Name=Application Timestamp
Sig[2].Value=524faabf
Sig[3].Name=Fault Module Name
Sig[3].Value=c1xx.dll
Sig[4].Name=Fault Module Version
Sig[4].Value=18.0.21005.1
Sig[5].Name=Fault Module Timestamp
Sig[5].Value=524faa90
Sig[6].Name=Exception Code
Sig[6].Value=c0000005
Sig[7].Name=Exception Offset
Sig[7].Value=0025236e
DynamicSig[1].Name=OS Version
DynamicSig[1].Value=10.0.10586.2.0.0.256.48
DynamicSig[2].Name=Locale ID
DynamicSig[2].Value=1033
UI[2]=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe
UI[3]=Microsoft (R) C//C++ Optimizing Compiler has stopped working
UI[4]=Windows can check online for a solution to the problem.
UI[5]=Check online for a solution and close the program
UI[6]=Check online for a solution later and close the program
UI[7]=Close the program
LoadedModule[0]=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\CL.exe
LoadedModule[1]=C:\Windows\SYSTEM32\ntdll.dll
LoadedModule[2]=C:\Windows\SYSTEM32\KERNEL32.DLL
LoadedModule[3]=C:\Windows\SYSTEM32\KERNELBASE.dll
LoadedModule[4]=C:\Program Files (x86)\MSBuild\12.0\bin\FileTracker.dll
LoadedModule[5]=C:\Windows\SYSTEM32\ADVAPI32.dll
LoadedModule[6]=C:\Windows\SYSTEM32\msvcrt.dll
LoadedModule[7]=C:\Windows\SYSTEM32\sechost.dll
LoadedModule[8]=C:\Windows\SYSTEM32\RPCRT4.dll
LoadedModule[9]=C:\Windows\SYSTEM32\SspiCli.dll
LoadedModule[10]=C:\Windows\SYSTEM32\CRYPTBASE.dll
LoadedModule[11]=C:\Windows\SYSTEM32\bcryptPrimitives.dll
LoadedModule[12]=C:\Windows\SYSTEM32\ole32.dll
LoadedModule[13]=C:\Windows\SYSTEM32\combase.dll
LoadedModule[14]=C:\Windows\SYSTEM32\GDI32.dll
LoadedModule[15]=C:\Windows\SYSTEM32\USER32.dll
LoadedModule[16]=C:\Windows\SYSTEM32\MSVCR120.dll
LoadedModule[17]=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\mspdb120.dll
LoadedModule[18]=C:\Windows\SYSTEM32\VERSION.dll
LoadedModule[19]=C:\Windows\SYSTEM32\IMM32.DLL
LoadedModule[20]=C:\Windows\SYSTEM32\CRYPTSP.dll
LoadedModule[21]=C:\Windows\system32\rsaenh.dll
LoadedModule[22]=C:\Windows\SYSTEM32\bcrypt.dll
LoadedModule[23]=C:\Windows\SYSTEM32\MSVCP120.dll
LoadedModule[24]=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\mspdbcore.dll
LoadedModule[25]=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\c2.dll
LoadedModule[26]=C:\Windows\SYSTEM32\SHLWAPI.dll
LoadedModule[27]=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\c1xx.dll
LoadedModule[28]=C:\Windows\system32\apphelp.dll
State[0].Key=Transport.DoneStage1
State[0].Value=1
FriendlyEventName=Stopped working
ConsentKey=APPCRASH
AppName=Microsoft (R) C//C++ Optimizing Compiler
AppPath=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\cl.exe
ApplicationIdentity=00000000000000000000000000000000
i really confused because i am compile this project many times with this steps and with this visual studio.
Edit 1:
i create new Win32Project and i put this code on that:
#include "stdafx.h"
# define LENGTH 20
typedef unsigned char uint8_t;
typedef uint8_t uint8;
struct test
{
uint8 intT[LENGTH] = {};
};
and when i compile that i got this error again:
Error 1 error C1001: An internal error has occurred in the compiler. \Projects\Win32Project1\Win32Project1\Win32Project1.cpp 13 1 Win32Project1
An "internal compiler error" (or ICE) is, by definition, a compiler bug. There could well be code in your program that's triggering that bug. Your crash seems to be triggered by the use of a non-static data member initialisation (NSDMI), and Microsoft admits that their support for NSDMIs in Visual Studio 2013 was unreliable at best:
Unfortunately, the code in our compiler (some of it written 30 years ago) for handling initialization suffers from many longstanding architectural limitations. This code was sufficient for C++03-style initialization, but NSDMI, a C++11 feature, caused it to exhibit these limitations as severe bugs.
Given this, you may also wish to try simply upgrading your toolchain.
However, it could also be that your installation is completely broken/corrupted.
Either way, your first task is to reinstall Visual Studio and see whether the problem persists. Perhaps try compiling the project on a different computer.
If that doesn't fix it, you need to produce a minimal testcase and submit it to the developers for review (at MS Connect). Please be sure to come back here and link us to the posted issue so that I can update the answer with any pertinent information from the developers (e.g. version the bug is fixed in).
OK Finally Problem Solved, Only Need Update Visual Studio 2013 to Visual Studio 2013 Update 5.
On Update 5 For Visual Studio 2013 this bug is fixed completely.
Thank you "Lightness Races in Orbit" And "Niall" for answer and helps :)
i am so happy
This is a ICE (an internal compiler error). It is cause by the code around line 256 of the WorldSocket.cpp file.
In that file; the class AuthSession, here uses non-static default member initialisation (NSDMI) with an array (on line 256) that is shown in the error message.
IIRC, VS2013 does not fully support the NSDMI feature. It was added to C++11 but VS2013 had limitations in its implementation of NSDMI.
The uint8 Digest[SHA_DIGEST_LENGTH] = {}; could just be too much for it to compile.

link.exe returns error LNK1181: cannot open input file 'C:\Program.obj'

I'm compiling with a Batch file containing
#echo off
set link=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\link
"%link%" external_input.obj periodic_dinger.obj flagger.obj monitor.obj main.obj libGui.lib libCore.lib libCint.lib libRIO.lib libNet.lib libHist.lib libGraf.lib libGraf3D.lib libGpad.lib libTree.lib libRint.lib libPostscript.lib libMatrix.lib libPhysics.lib libMathCore.lib libThread.lib
All the objects and libraries are in the same directory, which is the directory I'm executing the Batch file from, and also where the Batch file is located. I've tried adding the current directory to /LIBPATH:, but no luck. My LIB environment variable is
C:\Users\jroth\Data\online_monitor_v.0.5>echo %LIB%
"C:\Program Files\ (x86)\Microsoft Visual Studio 11.0\VC\LIB";"C:\Program Files
(x86)\Microsoft Visual Studio 11.0\VC\ATLMFC\LIB";"C:\Program Files (x86)\Window
s Kits\8.0\lib\win8\um\x86";
I made sure that everything was quoted. The same error came up when everything was unquoted. The error verbatim is
C:\Users\jroth\Data\online_monitor_v.0.5>make
Microsoft (R) Incremental Linker Version 11.00.50727.1
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\link
LINK : fatal error LNK1181: cannot open input file 'C:\Program.obj'
make.bat is the name of the batch file I'm using to link this, not a makefile.
I'm running vcvarsall.bat before doing any of this.
The problem was with the environment variable link that you used. The MS linker also uses this variable for flags.
From https://msdn.microsoft.com/en-us/library/6y6t9esh.aspx:
The LINK tool uses the following environment variables:
LINK, if defined. The LINK tool processes options and arguments defined in the LINK environment variable before processing the command line.
So you can't use set link=..., you'll have to use another name. _link will do fine.

The system cannot find the file specified in Visual Studio 2013 C++

I am learning C++ for the first day, went on to type in this code from the first Chapter of "C++ A Beginner's Guide":
#include <iostream>
using namespace std;
int main()
{
cout << "C++ is power prgramming.";
return 0;
}
then when I debug it, I get an error message saying:
"Unable to start program 'F:\Documents\Visual Studio 2013\Projects\Projects1\Debug\Project1.exe'.
The system cannot find the file specified."
The error in output shows:
1>CL : Command line warning D4024: unrecognized source file type '?', object file assumed
1> Microsoft (R) Incremental Linker Version 12.00.31101.0
1> Copyright (C) Microsoft Corporation. All rights reserved.
1>
1> /out:
1> ?.exe
1>LINK : fatal error LNK1146: no argument specified with option '/out:'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I looked though a few posts that seems similar but none of the answers helped me. I had tried to add Additional Library Directories in the properties but still doesn't help. Tried compiling before debugging but still same error came out.
I just installed Visual Studio today so there is not point of restoring Default.
What else can I do?
Thanks very much.

Getting started with GRETA Regular Expression Library

I'm required to work on GRETA Regular Expression Library, provided by Microsoft Research. I was unable to compile and run the sample program when used cl.exe provided with Visual Studio 2008. It gave some errors like:
D:\greta\greta-2.6.4>cl /EHsc num_match.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
num_match.cpp
d:\greta\greta-2.6.4\restack.h(355) : warning C4346: 'regex::hetero_stack<Alignm
entT,RuntimeTypeCheckT,AssumePodT,DynamicBlockSizeT,StaticBlockSizeT>::stack_nod
e::header' : dependent name is not a type
prefix with 'typename' to indicate a type
d:\greta\greta-2.6.4\restack.h(854) : see reference to class template in
stantiation 'regex::hetero_stack<AlignmentT,RuntimeTypeCheckT,AssumePodT,Dynamic
BlockSizeT,StaticBlockSizeT>' being compiled
d:\greta\greta-2.6.4\restack.h(355) : error C2923: 'regex::hetero_stack<Alignmen
tT,RuntimeTypeCheckT,AssumePodT,DynamicBlockSizeT,StaticBlockSizeT>::aligned_siz
eof' : 'regex::hetero_stack<AlignmentT,RuntimeTypeCheckT,AssumePodT,DynamicBlock
SizeT,StaticBlockSizeT>::stack_node::header'
It is not a valid template type argument for parameter 'T'.
Can anybody help me to get started with GRETA?