Skip to content

Commit d39060b

Browse files
authored
Add missing const in one of IString::startsWith methods (#7891)
Other `IString::startsWith` methods all have it but this doesn't, making this code not able to compile, ```cpp Name n; const Name& n2 = n; if (n2.startsWith("abc")) ... ``` because `n` here is a const reference. This situation can be easily created when using containers: ```cpp std::set<Name> names; for (auto &n : names) if (n.startswith("abc")) ... ``` Because `set`'s iterator gives a constant reference, this does not compile currently.
1 parent 882eafe commit d39060b

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/support/istring.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ struct IString {
8484
bool startsWith(IString str) const { return startsWith(str.str); }
8585

8686
// Disambiguate for string literals.
87-
template<int N> bool startsWith(const char (&str)[N]) {
87+
template<int N> bool startsWith(const char (&str)[N]) const {
8888
return startsWith(std::string_view(str));
8989
}
9090

0 commit comments

Comments
 (0)