Issue 110103
Summary Diagnose dangling assignments for std::initializer_list.
Labels clang:frontend, clang:memory-safety
Assignees
Reporter hokein
    See the example below, it would be nice for clang to diagnose this case.

https://godbolt.org/z/W3dhEzY6M

```cpp
#include <vector>
using namespace std;

int main() 
{
  // Good: Initializing an initializer_list object from the array extends the
  // lifetime of the array exactly like binding a reference to a temporary.
 initializer_list<int> a = {1, 2, 3};

  // Dangerous! the lifetime of the backing array is not extended for assignments.
  // 
  // A holds dangling pointers into backing array which are destroyed at the end of full _expression_.
  a = {2, 3, 4};
  for (int i : a) {
    i;
 }
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to