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

    <tr>
        <th>Summary</th>
        <td>
            C++23 lifetime extension in range-based for loops: Clang destroys temporaries bound to references by default member initializer early (without warning)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            c++23
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          hubert-reinterpretcast
      </td>
    </tr>
</table>

<pre>
    Clang normally warns that it fails to extend the lifetime of temporaries bound to member references by default member initializers in aggregate initialization.
It fails to even warn when the aggregate initialization occurs as a subexpression of a for-range-initializer.

Online compiler link (with two cases: one where the aggregate initialization occurs as a subexpression and another where it is the for-range-initializer): https://godbolt.org/z/T9zdrevv8

### SOURCE (`<stdin>`):
```cpp
extern "C" void exit(int);

struct A {
 int arr[1];
  ~A() noexcept(false) { throw 42; }
};

struct B {
  int x;
  const A &a = A{{0}};
  const int *begin() { return a.arr; }
  const int *end() { return &a.arr[1]; }
};

int main() {
  for (auto &&x : B{0}.a.arr) { exit(0); }
  //for (auto &&x : B{0}) { exit(0); }
}
```

### COMPILER INVOCATION:
```
clang++ -std=c++23 -Werror -xc++ -
```

### COMPILER OUTPUT:
(clean compile with no warnings)

### ACTUAL RUN OUTPUT:
```
$ ./a.out
libc++abi: terminating due to uncaught exception of type int
```

### EXPECTED RUN OUTPUT:
rc = 0

### COMPILER VERSION INFO (`clang++ -v`):
```
clang version 19.0.0git (https://github.com/llvm/llvm-project.git c0d03d28c58f3016eb25ce8d1160e11183d01735)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/wandbox/clang-head/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Candidate multilib: .;@m64
Selected multilib: .;@m64
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVl1v2zoS_TX0y8CCRNmy_OAHf2kRoBsXqdPdtwVFjiVuKdIgKdvpw_3tF5TkxE3Sr4sCQmKJnDlnhjOHw5yTlUZckOmKTDcj1vra2EXdlmj92KLUHu3RoufM-VFpxNNirZiuQBvbMKWe4MysduBr5kF6ODCpHHgDePGoBfgaQckDetkgmAN4bI7GMivRQWnasMNAg02JFiwe0KLmYekJBB5Yq_x1UWrpJVPyK1oHUgOrKosV8_iywrw0OiLxhsTLu1sqJ9QdTTjXqDtK37MGw3lrHTAHDFxb4uVo0blu5QAMDsaOLdMVjm_4DJD9351WUiNw0xylQgtK6i9AaH6WvgZ_NsCZQ0fSJRiNgZDFf8qIaQFMG1-jHRxJD9J17t4lSug8ANfeHwMDQgtCi8qI0igfGVsRWnwltNjPvwqLp1N-Gxehaf_Ap93jw3obYiJZTNK180Jqkm7DWwcwGGRx__Djsf8SSsJqIJSuCaVwMlIAXqQnNJfad7arW0jnbcs9LIHMhu8gtQdmLZmuEjLdPO8H-GsZ-NA5aIMXjsfg9MCUw_CNzFbga2vOMKEkXQGZbQac2eZ9zNUNZgd6ucHiRruOFs0YkHQDy7B5toqDu9nmzc5gT-iyxErqgWVgZNG3VgOLQkC3rF7ZoRZvrQJ29E0mfhRV8NSwW_Qr0sHYcJKs9Sb4JDS7QKiRazxRjzKAD6fVn_M3jPta-pm3n_l5-XEtnvdLcL3798e7D9sHuLv_vFsv93e7-7d117_yoFaErghdwdh5QdIN719pCuP_oLXGwvjCr1t-D3_3uP_4uH_BpjlXyPS1_aHrem069ZG6ciHgdz0u1_vH5Qd4eLx_4_MVFTqBiNCCRab1_Scly4E-K2VIt0fbSM281BWIFoMGtpqztqo99N0xCJp_Oga98b8U9Pa_H7fr_XbzHknLu0b4Wbo-bx8-3e3u4e6-2A0C8s35nL6nITdnCSe0nfwl8yiO4kqGJslfaZr0dVtG3DSEFkqdrv_GR2v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