Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#9474 closed Bugs (fixed)

boost/type_traits/has_new_operator.hpp causes compilation errors when macro "new" is defined

Reported by: myasnikovmaksim@… Owned by: John Maddock
Milestone: To Be Determined Component: type_traits
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc:

Description

It is a recommended practice to #define new DEBUG_NEW in order to detect memory leaks in MFC projects, but it causes compilation errors in boost/type_traits/has_new_operator.hpp due to undesirable macro substitution.
I suggest to hide this macro at the beginning of the file and restore it at the end. Attached patch is suitable only for Visual C++ compiler.
Best regards, Maksim.

Attachments (3)

has_new_operator.hpp.patch (966 bytes ) - added by anonymous 9 years ago.
has_new_operator.hpp (5.0 KB ) - added by anonymous 8 years ago.
has_new_operator.hpp.2.patch (390 bytes ) - added by myasnikovmaksim@… 7 years ago.
#undef BOOST_TT_AUX_MACRO_NEW_DEFINED

Download all attachments as: .zip

Change History (8)

by anonymous, 9 years ago

Attachment: has_new_operator.hpp.patch added

comment:1 by Steven Watanabe, 9 years ago

Recommended by who? You should never #define keywords.

comment:2 by myasnikovmaksim@…, 9 years ago

Microsoft, I guess :-)
I'm absolutely agree with about #defining keywords, but this happens.

in reply to:  2 comment:3 by viboes, 9 years ago

Replying to myasnikovmaksim@…:

Microsoft, I guess :-)
I'm absolutely agree with about #defining keywords, but this happens.

Please don't do this. Repalce instead the global ::new/::delete operators. http://stackoverflow.com/questions/8186018/how-to-properly-replace-global-new-delete-operators

comment:4 by John Maddock, 9 years ago

Resolution: fixed
Status: newclosed

Fixed in Git develop, but none the less as Viboes said: "don't do that"!

in reply to:  4 comment:5 by myasnikovmaksim@…, 8 years ago

Replying to johnmaddock:

Fixed in Git develop, but none the less as Viboes said: "don't do that"!

Thank you. Needless to say that keyword redefinition is evil, but ancient code can be tricky.
A minor adjustment if you please: there is no reason to keep macro BOOST_TT_AUX_MACRO_NEW_DEFINED defined after pop_macro("new") pragma.

by anonymous, 8 years ago

Attachment: has_new_operator.hpp added

by myasnikovmaksim@…, 7 years ago

#undef BOOST_TT_AUX_MACRO_NEW_DEFINED

Note: See TracTickets for help on using tickets.