My current goal is to create one (or as little as possible) line of code that will switch the remainder of the active compilation module to an unoptimized debug configuration. My first instincts were either:
FORCE_DEBUG;
or
#include "ForceDebug.h"
would be perfect. In my workspace, converting to a non-optimized debug configuration requires changing the pragma optimization level, but also #undef some macros and #define other macros.
The FORCE_DEBUG macro does not work, because it will need to execute the preprocessor directives #undef and #define, which, as I understand it, cannot be evaluated inside the macro.
Instead, I have a working version of #include "ForceDebug.h". But I want to inform the developer that they turned off optimization on this compilation module (so that they do not check it or do not check, so that it can be caught and fixed). Ideally, this message includes the file name of any file # includes "ForceDebug.h" or the current compilation unit.
Here's about ForceDebug.h
#pragma once
#pragma message("DISABLING OPTIMIZATION IN" COMPILATION_UNIT_FILE)
#undef _RELEASE
#define _DEBUG
#ifdef _MSC_VER
# pragma optimize("", off)
#else
# pragma GCC optimize("O0")
#endif
So the call site would look like Foo.cpp:
#define COMPILATION_UNIT_FILE "Foo.cpp"
#include "ForceDebug.h"
I can’t use __FILE__it because these are messages about ForceDebug.h when I want to report Foo.cpp.
If I could evaluate __FILE__inside Foo.cpp and pass the evaluated version to ForceDebug.h, that would be acceptable, but I tried recursive macro calls and still reported ForceDebug.h
"Foo.cpp" include clang Visual Studio?