<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/119945>119945</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [C++] [Strings] -- find_first_*(s, pos, n) & find_last_*(s, pos, n) give wrong result with String-Literal s, and n > than s-length
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          PN-03
      </td>
    </tr>
</table>

<pre>
    I'm using LLVM 19.1.5 MinGW and this issue only happens with String-Literals.

Here's the code to reproduce the issue:

```c++

 string s = ":";
  string x = "What a wonderful day to play. Arthur the Aardvark: has the best show";

  cout << "String Index: " << x.find_first_of(s.c_str(), 21, 60) << "\n";

  cout << "\n";
 for(size_t n = 1; n <= 10; n++){
    cout << "n = " << n << ", String-Literal Index: Find_First: " << x.find_first_of(":", 10, n);
 cout << ", Find_Last: " << x.find_last_of(":", x.length(), n) << endl;
 }
  
  cout << "\n";
  for(size_t n = 1; n <= 100; n *= 2){
    cout << "n = " << n << ", String-Literal Index: Find_First_Not: " << x.find_first_not_of(":", 10, n);
    cout << ", Find_Last_Not: " << x.find_last_not_of(":", x.length(), n) << endl;
  }
``` 
pos = 49 is the correct result for the Find_First/Find_Last Set.

pos = 10 for Find_First_Not and pos = 67 for Find_Last_Not Set


This is the Output:


String Index: 49

n = 1, String-Literal Index: Find_First: 49, Find_Last: 49
n = 2, String-Literal Index: Find_First: 49, Find_Last: 49
n = 3, String-Literal Index: Find_First: 49, Find_Last: 49
n = 4, String-Literal Index: Find_First: 33, Find_Last: 65
n = 5, String-Literal Index: Find_First: 18, Find_Last: 65
n = 6, String-Literal Index: Find_First: 18, Find_Last: 65
n = 7, String-Literal Index: Find_First: 16, Find_Last: 65
n = 8, String-Literal Index: Find_First: 16, Find_Last: 65
n = 9, String-Literal Index: Find_First: 16, Find_Last: 65
n = 10, String-Literal Index: Find_First: 16, Find_Last: 67

n = 1, String-Literal Index: Find_First_Not: 10, Find_Last_Not: 67
n = 2, String-Literal Index: Find_First_Not: 10, Find_Last_Not: 67
n = 4, String-Literal Index: Find_First_Not: 10, Find_Last_Not: 67
n = 8, String-Literal Index: Find_First_Not: 10, Find_Last_Not: 67
n = 16, String-Literal Index: Find_First_Not: 14, Find_Last_Not: 64
n = 32, String-Literal Index: Find_First_Not: 30, Find_Last_Not: 64
n = 64, String-Literal Index: Find_First_Not: 18446744073709551615, Find_Last_Not: 18446744073709551615
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0lktv4zYQxz8NfRlYEF96HHRwlLpdILstsEX3aMgSbalVSIOk8uinL0hJljd2vPIiBQwlJIe_4fxJzrAwptlLITLE7xC_XxSdrZXO_viyDOliq6rX7BMi8SN0ppF7eHj46zPgNMABh8-N_PUbFLICWzcGGmM6AUq2r1AXh4OQBp4bW8NXqxu5Xz40VuiiNQEKVyhc_Sa0QCQ2YGsBpaoEWAVaHLSqulL4Xg9EdNVPQFHY_0pE7tzP94LxdDCA6D0gQpy9-7pxGEdfxtFvdWGhgGclK6F3XQtV8eocH9riNYCVtnWnve9VoaunQv-D6Arqol_lVhgLplbPRwfeR6k6C4jmiObORR8ufJKVeHGzESHj6Euwa2S12TXa2I3aIZKYoNwYqxFJEEkRyYFg941CRNITJuK5vOr0OwPYKUc0zb9iY0H62DGid_7f3LdC3xyEJCmKe7nOuHIUbuyTp05J_mZzp6jXLtC1C_SHGkybRnK3MpK7laVDLG8DJXnPfijeQ7fFRfJL0Aq5t_WktTwRWciqHTyi-N6L8WOd5wgdDm2ycm3yP4u9-aKuCi7VLNHP1_ad7u978dpfdjJb_2EDjvfdbcRB9RecpdCMKUNrUVrQwnStdTvhu0_OHVkfFwxfhR3yzkjCoZ_zvXQ-mY0WUTxZjFE70JCOwtWffdbzfn_v7KGzU7IKV2_zAEv7_vGYzL48LD079J7Vg264hddB9KNAbD6I0jNQxI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