Skip to content

Commit

Permalink
Fix ctl::string_view const iteration issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Oct 29, 2024
1 parent baad1df commit a120bc7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ctl/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions test/ctl/string_view_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
}

0 comments on commit a120bc7

Please sign in to comment.