https://gcc.gnu.org/g:31ca0008418821367eaec1fa7750c18442d18c5e
commit r16-7253-g31ca0008418821367eaec1fa7750c18442d18c5e Author: Jakub Jelinek <[email protected]> Date: Tue Feb 3 09:18:34 2026 +0100 c++: Don't call cpp_translate_string on NULL string [PR123918] My P2246R1 patch caused diagnostics reported by running ubsan instrumented compiler on cpp26/static_assert1.C - if len is 0, we don't bother to allocate msg, so it stays NULL, and when I've added cpp_translate_string call, that can invoke memcpy (something, NULL, 0); in that case. While that is no longer UB in C2Y since N3322, libsanitizer doesn't know that yet and reports it anyway. While we could just do if (len) { ... } else msg = ""; there is really no point in trying to translate "" and allocate memory for that, so the following patch instead by passes that translation for len == 0. 2026-02-03 Jakub Jelinek <[email protected]> PR c++/123918 * semantics.cc (cexpr_str::extract): Bypass cpp_translate_string for len == 0. Diff: --- gcc/cp/semantics.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 3e1a86fae6ca..fb1be25edf5f 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12860,7 +12860,10 @@ cexpr_str::extract (location_t location, const char * & msg, int &len) cpp_string istr, ostr; istr.len = len; istr.text = (const unsigned char *) msg; - if (!cpp_translate_string (parse_in, &istr, &ostr, CPP_STRING, true)) + if (len == 0) + ; + else if (!cpp_translate_string (parse_in, &istr, &ostr, CPP_STRING, + true)) { error_at (location, "could not convert constexpr string from " "ordinary literal encoding to source character "
