[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228 --- Comment #19 from GCC Commits --- The releases/gcc-16 branch has been updated by Jonathan Wakely : https://gcc.gnu.org/g:05c0ad7b98a1b24ed3f04f2e5700bbaf9dc50bc3 commit r16-9207-g05c0ad7b98a1b24ed3f04f2e5700bbaf9dc50bc3 Author: Dragon Archer Date: Fri May 8 18:16:15 2026 + libstdc++: replace assert with __glibcxx_assert [PR125228] Unlike `__glibcxx_assert` which is guarded by `_GLIBCXX_ASSERTIONS` and enabled only in Debug build of libstdc++, `assert` is either always enabled, or always disabled if manually defining `NDEBUG` before `#include ` or `#include `. This not only makes `assert` inflexible, but also introduces extra runtime overhead and/or increased binary size in Release builds. Uses of `assert` without `NDEBUG` introduces `__FILE__` into the final library, and unconditionally checks the assertions. This patch replaces the uses of `assert` in ryu and debug.cc with `__glibcxx_assert`, and removed their direct dependency on ``. To avoid modifying the third-party ryu headers, this patch redefines `assert` to `__glibcxx_assert` when including the ryu headers. libstdc++-v3/ChangeLog: PR libstdc++/125228 * src/c++11/debug.cc: Replace assert with __glibcxx_assert, and remove the include of . * src/c++17/floating_to_chars.cc: Likewise, but redefine assert as __glibcxx_assert. Reviewed-by: Patrick Palka Reviewed-by: Jonathan Wakely (cherry picked from commit fe3c9c98bf52e1a01f903c3d685930019a57ce61)
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228 --- Comment #18 from GCC Commits --- The master branch has been updated by Jonathan Wakely : https://gcc.gnu.org/g:fe3c9c98bf52e1a01f903c3d685930019a57ce61 commit r17-553-gfe3c9c98bf52e1a01f903c3d685930019a57ce61 Author: Dragon Archer Date: Fri May 8 18:16:15 2026 + libstdc++: replace assert with __glibcxx_assert [PR125228] Unlike `__glibcxx_assert` which is guarded by `_GLIBCXX_ASSERTIONS` and enabled only in Debug build of libstdc++, `assert` is either always enabled, or always disabled if manually defining `NDEBUG` before `#include ` or `#include `. This not only makes `assert` inflexible, but also introduces extra runtime overhead and/or increased binary size in Release builds. Uses of `assert` without `NDEBUG` introduces `__FILE__` into the final library, and unconditionally checks the assertions. This patch replaces the uses of `assert` in ryu and debug.cc with `__glibcxx_assert`, and removed their direct dependency on ``. To avoid modifying the third-party ryu headers, this patch redefines `assert` to `__glibcxx_assert` when including the ryu headers. libstdc++-v3/ChangeLog: PR libstdc++/125228 * src/c++11/debug.cc: Replace assert with __glibcxx_assert, and remove the include of . * src/c++17/floating_to_chars.cc: Likewise, but redefine assert as __glibcxx_assert. Reviewed-by: Patrick Palka Reviewed-by: Jonathan Wakely
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228 --- Comment #17 from dragon-archer at outlook dot com --- (In reply to Jonathan Wakely from comment #13) > Please don't change src/c++17/fast_float/fast_float.h either, that's also a > third party library, and your change is completely unnecessary. The > libstdc++ code that includes fast_float.h already does: > > src/c++17/floating_from_chars.cc:# define FASTFLOAT_DEBUG_ASSERT > __glibcxx_assert > > So it's already using __glibcxx_assert and not assert. The third party > library does exactly the right thing and allows its assertions to be > tailored to the project's preferred form. And we do that. So you don't need > to change the code, it already does what you want. This has already been removed from the patch. (In reply to Jonathan Wakely from comment #14) > Thanks for the patch. Libstdc++ patches should be CC'd to the libstdc++ list > as well as gcc-patches. > > https://gcc.gnu.org/contribute.html > > We also need a copyright assignment or DCO sign-off under a real identity, > not an anonymous pseudonym. Got it. Should I send a new patch with the Signed-off-by?
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228 --- Comment #16 from Jonathan Wakely --- (In reply to Jonathan Wakely from comment #14) > Thanks for the patch. Libstdc++ patches should be CC'd to the libstdc++ list > as well as gcc-patches. Oh sorry, I see that you already did that (but it was in my spam folder, so I thought it hadn't gone to the libstdc++ list). > > https://gcc.gnu.org/contribute.html > > We also need a copyright assignment or DCO sign-off under a real identity, > not an anonymous pseudonym. This change is pretty mechanical, so maybe we don't need the legal paperwork.
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228 --- Comment #15 from Jonathan Wakely --- (In reply to Patrick Palka from comment #11) > Cool, I didn't know about the #pragma push/pop_macro, which seems like > exactly what we want here. Want to post your patch to the mailing list? It makes it a bit more robust, but isn't actually necessary. Simply not including guarantees that 'assert' isn't defined, and then we can define it to __glibcxx_assert.
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228 --- Comment #14 from Jonathan Wakely --- Thanks for the patch. Libstdc++ patches should be CC'd to the libstdc++ list as well as gcc-patches. https://gcc.gnu.org/contribute.html We also need a copyright assignment or DCO sign-off under a real identity, not an anonymous pseudonym.
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228 --- Comment #13 from Jonathan Wakely --- Please don't change src/c++17/fast_float/fast_float.h either, that's also a third party library, and your change is completely unnecessary. The libstdc++ code that includes fast_float.h already does: src/c++17/floating_from_chars.cc:# define FASTFLOAT_DEBUG_ASSERT __glibcxx_assert So it's already using __glibcxx_assert and not assert. The third party library does exactly the right thing and allows its assertions to be tailored to the project's preferred form. And we do that. So you don't need to change the code, it already does what you want.
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228 --- Comment #12 from dragon-archer at outlook dot com --- (In reply to Patrick Palka from comment #11) > (In reply to dragon-archer from comment #10) > > Created attachment 64398 [details] > > [PATCH v2] libstdc++: use __glibcxx_assert instead of assert > > > > How about this lighter patch? > Cool, I didn't know about the #pragma push/pop_macro, which seems like > exactly what we want here. Want to post your patch to the mailing list? Thanks for your appreciation. Patch sent at https://gcc.gnu.org/pipermail/gcc-patches/2026-May/716165.html
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228 --- Comment #11 from Patrick Palka --- (In reply to dragon-archer from comment #10) > Created attachment 64398 [details] > [PATCH v2] libstdc++: use __glibcxx_assert instead of assert > > How about this lighter patch? Cool, I didn't know about the #pragma push/pop_macro, which seems like exactly what we want here. Want to post your patch to the mailing list?
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228 dragon-archer at outlook dot com changed: What|Removed |Added Attachment #64397|0 |1 is obsolete|| --- Comment #10 from dragon-archer at outlook dot com --- Created attachment 64398 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64398&action=edit [PATCH v2] libstdc++: use __glibcxx_assert instead of assert How about this lighter patch?
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228
--- Comment #9 from Jonathan Wakely ---
--- a/libstdc++-v3/src/c++17/floating_to_chars.cc
+++ b/libstdc++-v3/src/c++17/floating_to_chars.cc
@@ -26,7 +26,6 @@
#include
#include
-#include
#include
#include
#include
@@ -106,6 +105,7 @@ namespace
namespace ryu
{
+#define assert __glibcxx_assert
#include "ryu/common.h"
#include "ryu/digit_table.h"
#include "ryu/d2s_intrinsics.h"
For debug.cc we need to be sure that we aren't going to recurse into the debug
mode code when we use our own assertion inside the debug mode code. It should
be OK, because __glibcxx_assert doesn't use the full debug mode machinery, even
when _GLIBCXX_DEBUG is defined. So I think your changes to debug.cc are OK.
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228 --- Comment #8 from Jonathan Wakely --- (In reply to dragon-archer from comment #5) > Created attachment 64397 [details] > [PATCH] libstdc++: use __glibcxx_assert instead of assert No, we are not going to change the ryu files. Those are imported from a third party project and should not be modified here. It just makes it harder to track upstream.
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228 --- Comment #7 from Jonathan Wakely --- Yes, that file should not be including at all (I incorrectly assumed it wasn't, and that only the ryu headers included assert.h)
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228
--- Comment #6 from dragon-archer at outlook dot com ---
(In reply to Jonathan Wakely from comment #4)
> We could do this so that Ryu assertions are only used when the libstdc++
> assertions are also enabled:
>
> --- a/libstdc++-v3/src/c++17/floating_to_chars.cc
> +++ b/libstdc++-v3/src/c++17/floating_to_chars.cc
> @@ -106,6 +106,9 @@ namespace
>
>namespace ryu
>{
> +#ifndef _GLIBCXX_ASSERTIONS
> +# define NDEBUG
> +#endif
> #include "ryu/common.h"
> #include "ryu/digit_table.h"
> #include "ryu/d2s_intrinsics.h"
`#define NDEBUG` here is useless, you should define it before `#include
`.
BTW, I recommend to replace `assert` with `__glibcxx_assert` directly and
remove `#include `, which should be clearer. I've generated a patch
for this above.
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228 --- Comment #5 from dragon-archer at outlook dot com --- Created attachment 64397 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64397&action=edit [PATCH] libstdc++: use __glibcxx_assert instead of assert
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228
Jonathan Wakely changed:
What|Removed |Added
Last reconfirmed||2026-05-08
Ever confirmed|0 |1
CC||ppalka at gcc dot gnu.org
Status|UNCONFIRMED |NEW
--- Comment #4 from Jonathan Wakely ---
We could do this so that Ryu assertions are only used when the libstdc++
assertions are also enabled:
--- a/libstdc++-v3/src/c++17/floating_to_chars.cc
+++ b/libstdc++-v3/src/c++17/floating_to_chars.cc
@@ -106,6 +106,9 @@ namespace
namespace ryu
{
+#ifndef _GLIBCXX_ASSERTIONS
+# define NDEBUG
+#endif
#include "ryu/common.h"
#include "ryu/digit_table.h"
#include "ryu/d2s_intrinsics.h"
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228 --- Comment #3 from Jonathan Wakely --- (In reply to Drea Pinski from comment #1) > These are all __glibcxx_assert you are complaining about. No, there are uses of 'assert' in the third-party ryu lib that we use: src/c++17/ryu/common.h: assert(v < 10);
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228 --- Comment #2 from Drea Pinski --- libstdc++.so includes library functions which uses these and the sources are never built with _GLIBCXX_ASSERTIONS turned off. Well src/c++11/debug.cc but that is similar really.
[Bug libstdc++/125228] Avoid using assert in libstdc++
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125228 --- Comment #1 from Drea Pinski --- These are all __glibcxx_assert you are complaining about.
