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

    <tr>
        <th>Summary</th>
        <td>
            Unnecessary warning for the fixed range-based for loop in C++23
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          josuttis
      </td>
    </tr>
</table>

<pre>
    Consider (for the complete example, see: https://www.godbolt.org/z/oajGrd56M):

```
std::vector<std::string> getData() {  return {"OK?", "other", "ok"}; }

for (auto c : getData()[0]) {
  std::cout << c << '\n';
}
```

Iterating over a reference to an rvalue was an error before C++23, but since C++23 it no longer is.

Thanks for making the approporiate fix in clang. However, there is still a warning as if we don't have the fix. 

```
<source>:13:17: warning: object backing the pointer will be destroyed at the end of the full-expression [-Wdangling-gsl]
   13 |   for (auto c : getData()[0]) {
      |                 ^~~~~~~~~
1 warning generated.
ASM generation compiler returned: 0
<source>:13:17: warning: object backing the pointer will be destroyed at the end of the full-expression [-Wdangling-gsl]
   13 |   for (auto c : getData()[0]) {
      |                 ^~~~~~~~~
```

So, this warning should go away with C++23. Not sure how easy it is to fix it, though, as this is a special behavior just in the range-based for loop.


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkVUFv8zYP_jXMhUjgSHYcH3xokub7huHdDu-GnWWbsdWqYiDJcbvDfvvAxE1b4MUOu04IJEoRyYcPScvEaHtPVEOxg-KwMGMaONRPHMeUbFw03L3Ve_bRdhQQ1PbEAdNA2PLL2VEipFcjEqg9RiLQDzikdI6gH0AdQR2naVr13DXs0opDD-r4J6gjm6f_ha7YfANVydXsANn7vMnm33UbUycX9MOF2sQB9P5-ElOwvgf9iD2lg0kG1BZUhVDuEAOlMXiRQalffwZ9BKUEJSjFaaDwafsscnkAvUNZPoGRcEFtzZgYW5TovriCYpdBcZid3lQQ7w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