Enable lightweight libstdc++ assertions

Add the GN argument enable_safe_libstdcxx, that enables libstdc++
lightweight assertions, that protect against different bad conditions
as invalid array indexes.

Bug: 1497935
Change-Id: Icb8e85f47295d258bc5ec7bdd32fa58f06b4dcb2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4994044
Commit-Queue: José Dapena Paz <[email protected]>
Reviewed-by: Dirk Pranke <[email protected]>
Reviewed-by: Nico Weber <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1266874}
diff --git a/base/libcpp_hardening_test.cc b/base/libcpp_hardening_test.cc
index 4224447..b1f4d99 100644
--- a/base/libcpp_hardening_test.cc
+++ b/base/libcpp_hardening_test.cc
@@ -12,7 +12,11 @@
 
 // TODO(thakis): Remove _LIBCPP_ENABLE_ASSERTIONS here once
 // pnacl-saigo's libc++ is new enough.
-#if !_LIBCPP_ENABLE_ASSERTIONS && \
+#if defined(__GLIBCXX__)
+#if !defined(_GLIBCXX_ASSERTIONS)
+#error "libstdc++ assertions should be enabled"
+#endif
+#elif !_LIBCPP_ENABLE_ASSERTIONS && \
     _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE
 #error "_LIBCPP_HARDENING_MODE not defined"
 #endif