Fix ctl::string_view const iteration issue

This commit is contained in:
Justine Tunney 2024-10-28 17:41:57 -07:00
parent baad1df71d
commit a120bc7149
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
2 changed files with 12 additions and 2 deletions

View file

@ -109,12 +109,12 @@ struct string_view
return p[n - 1];
}
constexpr const_iterator begin() noexcept
constexpr const_iterator begin() const noexcept
{
return p;
}
constexpr const_iterator end() noexcept
constexpr const_iterator end() const noexcept
{
return p + n;
}

View file

@ -16,6 +16,7 @@
// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#include "ctl/string.h"
#include "ctl/string_view.h"
#include "libc/mem/leaks.h"
#include "libc/str/str.h"
@ -172,5 +173,14 @@ main(int argc, char* argv[])
return 32;
}
{
ctl::string b;
const ctl::string_view s = "hi";
for (char c : s)
b += c;
if (b != "hi")
return 2;
}
CheckForMemoryLeaks();
}