Skip to content

Add missing const in one of IString::startsWith methods#7891

Merged
aheejin merged 1 commit intoWebAssembly:mainfrom
aheejin:startswith
Sep 9, 2025
Merged

Add missing const in one of IString::startsWith methods#7891
aheejin merged 1 commit intoWebAssembly:mainfrom
aheejin:startswith

Conversation

@aheejin
Copy link
Copy Markdown
Member

@aheejin aheejin commented Sep 9, 2025

Other IString::startsWith methods all have it but this doesn't, making this code not able to compile,

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:

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.

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.
@aheejin aheejin requested a review from kripken September 9, 2025 03:02
@aheejin aheejin merged commit d39060b into WebAssembly:main Sep 9, 2025
16 checks passed
@aheejin aheejin deleted the startswith branch September 9, 2025 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants