#include "Stroika/Foundation/StroikaPreComp.h"#include "Sanitizer.inl"Go to the source code of this file.
Is this built WITH a sanitizer? Debug::kBuiltWithAddressSanitizer, kBuiltWithThreadSanitizer and kBuiltWithUndefinedBehaviorSanitizer are the answers. (Which sanitizers it COULD be built with is a question about the toolchain and configuration -
Stroika deliberately defines no macro for this. Where you need the answer at compile time - in an #if - use the test documented on each variable, which is exactly the test that variable is defined with. None of them is ISO C++: o SANITIZE_ADDRESS and SANITIZE_THREAD are a g++ convention, which MSVC follows for the address sanitizer, and clang does from clang 22. o has_feature is a clang extension, which g++ adopted in g++ 14; MSVC has none (as of MSVC 19.51, VS 2026). o Nothing defines __SANITIZE_UNDEFINED (as of g++ 16, clang 22 and MSVC 19.51).
So a test must allow for __has_feature not existing - and "#if defined(__has_feature) && __has_feature (x)" does NOT: where it does not exist, the second half is still a syntax error. Nest the #if, as each variable's test does.
What each compiler provides, at compile time (as of g++ 16, clang 22, Apple clang 17 and MSVC 19.51):
address thread undefined behavior g++ before 14 __SANITIZE_ADDRESS__ __SANITIZE_THREAD__ (nothing) g++ 14 and later both both __has_feature clang before 22 (and Apple clang) __has_feature __has_feature __has_feature clang 22 and later both both __has_feature MSVC __SANITIZE_ADDRESS__ (no such sanitizer) (no such sanitizer)
The Stroika_Foundation_Debug_ATTRIBUTE_NO_SANITIZE_* macros are the one exception, since an attribute cannot be a variable. Each is defined for every compiler that has the attribute, whether or not built with that sanitizer - because a compiler ignores the attribute when not. (Were that not so, each definition would go inside its sanitizer's compile-time test.) All use the one generic attribute, no_sanitize ("address" / "thread" / "undefined" ...), wherever __has_attribute (no_sanitize) says the compiler has it (g++ from 8, clang) - the way boost and zstd do - plus MSVC's own __declspec (no_sanitize_address) for its one sanitizer.
Definition in file Sanitizer.h.