Work around a Clang 3.7 bug affecting constexpr insert()

The iterator-based insert(const_iterator, size_type, value_type)
function relies on traits_type::move() to shift the existing null
terminator to its new position. Clang 3.7's constexpr evaluator does not
handle this correctly, causing the following test to fail:

  static_string<3>{"ab"}.insert(2, 1, 'c') == "abc"

Add an explicit term() call, guarded by a preprocessor conditional for
Clang 3.7, to ensure proper null termination.
This commit is contained in:
Gennaro Prota
2025-12-18 10:35:43 +01:00
committed by Gennaro Prota
parent 2175496c55
commit 6f0c00b268

View File

@@ -6707,6 +6707,9 @@ insert(
traits_type::move(&curr_data[index + count], &curr_data[index], curr_size - index + 1);
traits_type::assign(&curr_data[index], count, ch);
this->size_impl(curr_size + count);
#if defined(__clang__) && __clang_major__ == 3 && __clang_minor__ == 7
term();
#endif
return &curr_data[index];
}