Please consider this simplified c++14 program:
#include <iostream>
struct A
{
A() { std::cout << "A() "; }
~A() { std::cout << "~A() "; }
};
int main()
{
auto l = std::initializer_list<A>{A()};
std::cout << ". ";
}
https://gcc.godbolt.org/z/1GWvGfxne
GCC prints here
A() . ~A()
Meaning that std::initializer_list
is destructed at the end of scope.
Clang prints:
A() ~A() .
Destroying std::initializer_list
in the line where it is constructed.
Are both compiler behave correctly here or one of them is wrong?