Open
Description
Issue description
The common.h
header uses #undef _DEBUG
before including the Python headers (I don't know why, but I guess it's important).
When it later restores the macro it uses #define _DEBUG
, which may be different from the original definition of the macro that happens to be 1 for example.
As a result subsequent code that expects _DEBUG to have a value will not compile.
I ran into this when including tbb.h (Threading Building Blocks) after pybind11.h, the TBB headers do expect _DEBUG to have a value.
This can be fixed by using #pragma push_macro("_DEBUG")
before the #undef and #pragma pop_macro("_DEBUG")
in place of the #define.
The push_macro pragma is a VC++ feature, not sure if other compilers have it, but this is done just for _MSC_VER anyway.
Reproducible example code
#include "pybind11/pybind11.h"
#if _DEBUG
#pragma message( "debug" )
#endif