[regex]Including regex.hpp causes error in an skeleton win32 project of VS.net2003 with MFC support

Hello, I have done a test, on WinXP + VS.net 2003, with regex lib as follows , A created a new 'Win32 Console Project', I selected MFC and pre-compiled header support. Leave other settings default. Then I created a skeleton project that can compile. Then I added #include <boost/regex.hpp> in the main cpp file. When I then compiled the program in debug mode, I got a "error C2665" at regex_raw_buffer.hpp(177) - “operator new. When I compiled it in release mode, it's Ok. Anybody know how about this phenomenom? Thanks Max

Wang Weiwei wrote:
Hello,
I have done a test, on WinXP + VS.net 2003, with regex lib as follows ,
A created a new 'Win32 Console Project', I selected MFC and pre-compiled header support. Leave other settings default.
Then I created a skeleton project that can compile. Then I added
#include <boost/regex.hpp>
in the main cpp file. When I then compiled the program in debug mode, I got a "error C2665" at regex_raw_buffer.hpp(177) - “operator new. When I compiled it in release mode, it's Ok.
Anybody know how about this phenomenom?
Weird, no. Regex is used and tested with VC8 a lot, although I admit I'm not in a position to test it with MFC. It's not as simple as adding: #include <new> to the top of that file is it? John.

John Maddock wrote:
Wang Weiwei wrote:
Hello,
I have done a test, on WinXP + VS.net 2003, with regex lib as follows ,
A created a new 'Win32 Console Project', I selected MFC and pre-compiled header support. Leave other settings default.
Then I created a skeleton project that can compile. Then I added
#include <boost/regex.hpp>
in the main cpp file. When I then compiled the program in debug mode, I got a "error C2665" at regex_raw_buffer.hpp(177) - “operator new. When I compiled it in release mode, it's Ok.
Anybody know how about this phenomenom?
Weird, no.
Regex is used and tested with VC8 a lot, although I admit I'm not in a position to test it with MFC. It's not as simple as adding:
#include <new>
to the top of that file is it?
John.
<educated guess> MFC does some nasty things like "#define new DEBUG_NEW". And I bet regex_raw_buffer.hpp(177) has an invocation of placement new. Try including the boost headers before the MFC headers, or find where MFC is monkeying with the definition of "new" and delete it. </educated guess> -- Eric Niebler Boost Consulting www.boost-consulting.com

Eric Niebler wrote:
<educated guess>
MFC does some nasty things like "#define new DEBUG_NEW". And I bet regex_raw_buffer.hpp(177) has an invocation of placement new. Try including the boost headers before the MFC headers, or find where MFC is monkeying with the definition of "new" and delete it.
</educated guess>
Ah, that might do it, it's not a placement new, it's a call to ::operator new. There's no way to suppress macro expansion on a non-function macro either is there? Thanks for the hint, John.

On Sat, 15 Jul 2006 18:12:57 +0100, "John Maddock" <john@johnmaddock.co.uk> wrote:
Ah, that might do it, it's not a placement new, it's a call to ::operator new. There's no way to suppress macro expansion on a non-function macro either is there?
AFAIK, no, but nobody can be sure of any pp statement without talking to Paul Mensonides, first :) You could detect whether "new" remains the same after an attempted expansion or not, though. Quite depressing, I know. As you'll see, this causes problems to themselves too: <http://support.microsoft.com/kb/317799/EN-US/> -- [ Gennaro Prota, C++ developer for hire ] [ resume: available on request ]

Gennaro, I think a third option in addition to the two provided in <http://support.microsoft.com/kb/317799/EN-US/> would be to separate user interface and business logic elements. It may be that the original poster does not need to include regex in the same source file as MFC. Just a thought. Regards, George.

The user, or Boost in the some prefix/suffix headers, could do something like: // prefix... #if defined(new) #undef new #define BOOST_NEW_DEFINED #endif // Boost includes... // suffix... #if defined(BOOST_NEW_DEFINED) #if defined(BOOST_MSVC) && defined(_DEBUG) #define new DEBUG_NEW #endif #endif -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com -- 102708583/icq - grafikrobot/aim - grafikrobot/yahoo
participants (6)
-
Eric Niebler
-
Gennaro Prota
-
George M. Garner Jr.
-
John Maddock
-
Rene Rivera
-
Wang Weiwei