Search

Cannot define placement new in any project where another file #includes <new> directly or indirectly by David Librik

Active

1
0
Sign in
to vote
Type: Bug
ID: 768788
Opened: 10/25/2012 10:24:07 PM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
If you have a C++ file in your program which defines a placement new function, and another C++ file which #includes <new> either directly or indirectly (i.e. a different C++ header that happens to #include <new>), you will get multiple LNK2005 errors.

This only happens with the Visual Studio 2012 toolchain. The older toolchains (Visual Studio 2008, 2010) compile and link it just fine.
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling Version

Visual Studio 2012

Steps to reproduce

1. Download the attached .zip file, placement-new-error.zip, and unzip it into a working directory.
2. Get a command prompt with Visual Studio 2012 tools (for instance, by running VCVARS32.BAT, or opening "VS 2012 Native Tools Command Prompt"), and CD to the working directory in step 1.
3. Compile and link the two files, file1.cpp and file2.cpp, as follows. (The switch /EHsc is only used to quiet an unrelated warning message.)
cl /EHsc file1.cpp file2.cpp
4. Notice the error messages:
file2.obj : error LNK2005: "void * __cdecl operator new(unsigned int,void *)" (??2@YAPAXIPAX@Z) already defined in file1.obj
libcpmt.lib(xthrow.obj) : error LNK2005: "void * __cdecl operator new (unsigned int,void *)" (??2@YAPAXIPAX@Z) already defined in file1.obj
libcpmt.lib(syserror.obj) : error LNK2005: "void * __cdecl operator new (unsigned int,void *)" (??2@YAPAXIPAX@Z) already defined in file1.obj
file1.exe : fatal error LNK1169: one or more multiply defined symbols found
5. Repeat steps 1-4 with a Visual Studio 2010 command prompt. The files will compile and link with no errors.

Product Language

English

Operating System

Windows 7 SP1

Operating System Language

English

Actual results

/out:file1.exe
file1.obj
file2.obj
file2.obj : error LNK2005: "void * __cdecl operator new(unsigned int,void *)" (??2@YAPAXIPAX@Z) already defined in file1.obj
libcpmt.lib(xthrow.obj) : error LNK2005: "void * __cdecl operator new (unsigned int,void *)" (??2@YAPAXIPAX@Z) already defined in file1.obj
libcpmt.lib(syserror.obj) : error LNK2005: "void * __cdecl operator new (unsigned int,void *)" (??2@YAPAXIPAX@Z) already defined in file1.obj
file1.exe : fatal error LNK1169: one or more multiply defined symbols found

Expected results

/out:file1.exe
file1.obj
file2.obj
File Attachments
File Name Submitted By Submitted On File Size  
placement-new-error.zip 10/25/2012 325 bytes
placement-new-error.zip 10/25/2012 325 bytes
Sign in to post a comment.
Posted by Microsoft on 10/26/2012 at 1:34 AM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 10/25/2012 at 10:50 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.