build: enable extra runtime checks in libstdc++/libc++ in debug mode
Change-Id: Id5991ef851c84e09f301f8868001a4b30f1e54a0
diff --git a/.waf-tools/default-compiler-flags.py b/.waf-tools/default-compiler-flags.py
index 48f4274..2941fe1 100644
--- a/.waf-tools/default-compiler-flags.py
+++ b/.waf-tools/default-compiler-flags.py
@@ -175,6 +175,9 @@
'-Wno-error=maybe-uninitialized', # Bug #1615
]
flags['LINKFLAGS'] += self.__linkFlags
+ # Enable assertions in libstdc++
+ # https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
+ flags['DEFINES'] += ['_GLIBCXX_ASSERTIONS=1']
return flags
def getOptimizedFlags(self, conf):
@@ -236,6 +239,13 @@
def getDebugFlags(self, conf):
flags = super().getDebugFlags(conf)
flags['CXXFLAGS'] += self.__cxxFlags
+ # Enable assertions in libc++
+ if self.getCompilerVersion(conf) >= (18, 0, 0):
+ # https://libcxx.llvm.org/Hardening.html
+ flags['DEFINES'] += ['_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE']
+ elif self.getCompilerVersion(conf) >= (15, 0, 0):
+ # https://releases.llvm.org/15.0.0/projects/libcxx/docs/UsingLibcxx.html#enabling-the-safe-libc-mode
+ flags['DEFINES'] += ['_LIBCPP_ENABLE_ASSERTIONS=1']
return flags
def getOptimizedFlags(self, conf):