diff --git a/ctl/string_view.h b/ctl/string_view.h index 64a895799f2..4b237f9d501 100644 --- a/ctl/string_view.h +++ b/ctl/string_view.h @@ -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; } diff --git a/test/ctl/string_view_test.cc b/test/ctl/string_view_test.cc index a82743e153f..43e52672827 100644 --- a/test/ctl/string_view_test.cc +++ b/test/ctl/string_view_test.cc @@ -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(); }