Search

MFC C++ fails to compile use of codecvt_utf8 in Debug Configuration by DrK273

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 683483
Opened: 8/9/2011 2:36:46 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
2
Workaround(s)
0
User(s) can reproduce this bug
I wish to use codecvt_utf8 to write UTF-8 data to a std::wofstream file in a MFC C++ application. Compiles and works OK in the Release configuration. Fails to compile in Debug configuration.

Workaround is to delete the following lines always added by the MFC project Wizard. However, I do not wish to do this in my large MFC application.

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

It seems that the 'new' operator in std::codecvt_utf8 conflicts with the MFC 'DEBUG_NEW' operator.
Details (expand)

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

Visual Studio 2010 SP1

Steps to reproduce

Create a new Win32 Console project and specify use of MFC. Add the following includes to the main source file.

#include <fstream>
#include <locale>
#include <codecvt>

Add the following source to the _tmain routine.

std::wofstream outfile;

std::locale UTF8locale(std::locale::empty(), new std::codecvt_utf8<wchar_t>);
outfile.open("utf8.txt");
outfile.imbue(UTF8locale);

// Write out some non-Latin characters
outfile << _T("UTF8 - Недопустимое") << endl;

outfile.close();

Try to compile in both Debug and Release configurations. The Debug compile fails with the compiler error messages below. The Release compile suceeds and runs OK.

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

In Debug - compiler errors:
error C2661: 'std::locale::facet::operator new' : no overloaded function takes 3 arguments
error C2664: 'std::locale::locale(const char *,std::locale::category)' : cannot convert parameter 1 from 'std::locale' to 'const char *'

Expected results

No compile errors in any configuration.
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 1/6/2012 at 4:39 PM
Hi,

Thanks for reporting this bug. We've fixed it, and the fix will be available in VC11.

According to the Standard, macroizing keywords when including Standard Library headers triggers undefined behavior, and VC11 will emit a hard #error when it detects this. However, macroizing "new" is unfortunately very common, so we've added special guards to all C++ Standard Library headers that will grant them immunity to macroized "new".

If you have any further questions, feel free to E-mail me at stl@microsoft.com .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by DrK273 on 9/15/2011 at 8:15 AM
It is over 5 weeks since I submitted this report and nearly 3 weeks since I asked for an update. Please provide an update as to the status of this issue?

Have you confirmed the issue?

Do you intend to fix it in this release of Visual Studio (2010)?
Posted by DrK273 on 8/29/2011 at 3:46 AM
Is there any update please?
Posted by MS-Moderator10 [Feedback Moderator] on 8/9/2011 at 7:11 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 8/9/2011 at 2:50 AM
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.
Posted by yfital on 12/24/2012 at 12:57 AM
FYI, another work around is to just write

std::locale utf8(std::locale(), ::new std::codecvt_utf8<wchar_t>);

That will force the compiler to use the global new, instead of the locale new
Posted by DrK273 on 8/9/2011 at 2:40 AM
Workaround is to delete the following lines in the source file that are always added by the MFC project Wizard.

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

But this should not be required!