]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Use const_cast to workaround tm_zone being non-const
authorJonathan Wakely <jwakely@redhat.com>
Wed, 26 Mar 2025 17:45:06 +0000 (17:45 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 27 Mar 2025 15:26:32 +0000 (15:26 +0000)
commit16766d5a0c4a946d3ba9255a99621975b9773e18
treea5b484c686a272b326e0a692eb0fbf7b6522d848
parentfd3bb314052f04f9357b4dce89fcb61ecfd3a83b
libstdc++: Use const_cast to workaround tm_zone being non-const

Iain reported that he's seeing this on Darwin:

include/bits/chrono_io.h:914: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

This is because the BSD definition ot tm::tm_zone is a char* (and has
been since 1987) rather than const char* as in Glibc and POSIX.1-2024.

We can fix it by using const_cast<char*> when setting the tm_zone
member. This should be safe because libc doesn't actually write anything
to tm_zone; it's only non-const because the BSD definition predates the
addition of the const keyword to C.

For targets where it's a const char* the cast won't matter because it
will be converted back to const char* on assignment anyway.

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (__formatter_chrono::_M_c): Use
const_cast when setting tm.tm_zone.

Reviewed-by: Iain Sandoe <iain@sandoe.co.uk>
libstdc++-v3/include/bits/chrono_io.h