D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20783 - std.string.lastIndexOf doesn't work correctly in CTFE
Summary: std.string.lastIndexOf doesn't work correctly in CTFE
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-04-28 11:55 UTC by Tomáš Chaloupka
Modified: 2020-04-29 10:18 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Tomáš Chaloupka 2020-04-28 11:55:47 UTC
```
pragma(msg, "aa".lastIndexOf("ab"));
```

Returns 0 instead of -1.

Problem seems to be with:
https://github.com/dlang/phobos/blob/ffca395ed2e9fd31cdb8e3e67adb8ddfba2607ac/std/string.d#L1345

as it continues foreach loop that should be stopped and instead upper for loop should continue with next character.
Comment 1 Dlang Bot 2020-04-29 00:55:13 UTC
@wolframw created dlang/phobos pull request #7465 "Fix Issue 20783 - std.string.lastIndexOf doesn't work correctly in CTFE" fixing this issue:

- Fix Issue 20783 - std.string.lastIndexOf doesn't work correctly in CTFE

https://github.com/dlang/phobos/pull/7465
Comment 2 Dlang Bot 2020-04-29 10:18:46 UTC
dlang/phobos pull request #7465 "Fix Issue 20783 - std.string.lastIndexOf doesn't work correctly in CTFE" was merged into master:

- c57990ceda8e0108554abde9eed0fc04e4041529 by wolframw:
  Fix Issue 20783 - std.string.lastIndexOf doesn't work correctly in CTFE

https://github.com/dlang/phobos/pull/7465