Skip to content

Commit a120bc7

Browse files
committed
Fix ctl::string_view const iteration issue
1 parent baad1df commit a120bc7

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

ctl/string_view.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ struct string_view
109109
return p[n - 1];
110110
}
111111

112-
constexpr const_iterator begin() noexcept
112+
constexpr const_iterator begin() const noexcept
113113
{
114114
return p;
115115
}
116116

117-
constexpr const_iterator end() noexcept
117+
constexpr const_iterator end() const noexcept
118118
{
119119
return p + n;
120120
}

test/ctl/string_view_test.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1717
// PERFORMANCE OF THIS SOFTWARE.
1818

19+
#include "ctl/string.h"
1920
#include "ctl/string_view.h"
2021
#include "libc/mem/leaks.h"
2122
#include "libc/str/str.h"
@@ -172,5 +173,14 @@ main(int argc, char* argv[])
172173
return 32;
173174
}
174175

176+
{
177+
ctl::string b;
178+
const ctl::string_view s = "hi";
179+
for (char c : s)
180+
b += c;
181+
if (b != "hi")
182+
return 2;
183+
}
184+
175185
CheckForMemoryLeaks();
176186
}

0 commit comments

Comments
 (0)