[all-commits] [llvm/llvm-project] 9032e9: [libc][cpp::string] Do not include null terminator...

Jackson Stogel via All-commits all-commits at lists.llvm.org
Fri Jul 24 14:22:51 PDT 2026


  Branch: refs/heads/users/jtstogel/string-capacity-fix
  Home:   https://github.com/llvm/llvm-project
  Commit: 9032e944d3fc1bb58fd970a4382de176227e71c9
      https://github.com/llvm/llvm-project/commit/9032e944d3fc1bb58fd970a4382de176227e71c9
  Author: jtstogel <jtstogel at gmail.com>
  Date:   2026-07-24 (Fri, 24 Jul 2026)

  Changed paths:
    M libc/src/__support/CPP/string.h
    M libc/test/src/__support/CPP/string_test.cpp

  Log Message:
  -----------
  [libc][cpp::string] Do not include null terminator in capacity()

Currently, `capacity()` includes the null terminator of the backing buffer, which does not align with C++20's `std::string`. That is, `s.reserve(s.capacity())` should be a no-op. While there's no requirement these be in-sync, it is less surprising to align its behavior.

Also, this fixes the case where `reserve()` is called on an empty string, where previously the null terminator was not set.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list