Community
cancel
Showing results for 
Search instead for 
Did you mean: 
David_F_10
Beginner
63 Views

Invalid constant expression if _DEBUG macro doesn't have value

We currently use the Python libraries in Boost and Intel TBB. The libraries in Boost undefine the MSVC macro _DEBUG then subsequently redefine it without any value. In TBB_Config.h the macro TBB_USE_DEBUG is set from the value of _DEBUG. When TBB_USE_DEBUG is later used in #if statements within the same header file the preprocessor cannot evaluate the expression and pre-processing fails.

Looking at the documentation on MSDN the value that _DEBUG is set to isn't stated therefore it shouldn't be assumed the value will be 1. Additionally having _DEBUG set to a value other than 1 may cause inconsistent behaviour too.

Currently the code in TBB_CONFIG.h is:

#ifndef TBB_USE_DEBUG
#ifdef _DEBUG
#define TBB_USE_DEBUG _DEBUG // This assumes _DEBUG is evaluable
#else
#define TBB_USE_DEBUG 0
#endif
#endif /* TBB_USE_DEBUG */

I propose the following fix:

#define TBB_USE_DEBUG 1 // Should always be evaluable

Thanks,

David

0 Kudos
3 Replies
Alexei_K_Intel
Employee
63 Views

Hi David,

Sorry for a long response. There are several moments that should be considered. On the one hand, MSDN states that "The compiler defines _DEBUG when you specify the /MTd or /MDd option.", on the other hand, it also states "_DEBUG Defined as 1 when the /LDd, /MDd, or /MTd compiler option is set. Otherwise, undefined." One more aspect is that "_DEBUG = 0" usually supposed to mean "no debug".

The current approach satisfies the following conditions:

  1. "_DEBUG is undefined" means "no debug"
  2. "_DEBUG defined to something that is evaluated to 0" means "no debug"
  3. "_DEBUG defined to something that is evaluated to non-zero value" means "debug"
  4. "_DEBUG defined to nothing (empty)" causes compile-time error.

The proposed solution solves the bullet #4 but breaks the bullet #2. The both bullets are not covered by MSDN but used by the community, so it does not seem acceptable to break one for the sake of another.

We are working on the solution that supports the bullet #4 as "_DEBUG defined to nothing (empty)" means "debug" but does not break the bullet #2. However, I cannot promise you exact date when it is available in the product. Sorry for inconveniences

Regards, Alex

Alexei_K_Intel
Employee
63 Views

Hi David,

The issue should be fixed in the latest update (starting from Intel TBB 2017 Update 2). Could you evaluate it, please?

Regards, Alex

David_F_10
Beginner
63 Views

Hi Alex,

We have tested this locally - the changes correctly detect the state of the _DEBUG macro now.

Thanks for looking into this and resolving it,

David