Open llvmbot opened 8 years ago
This is DR core issue 1343 "Sequencing of non-class initialization". Clang is conformant to P0570R0 (and thus to C++17).
The problem seems to be the aggregate initialization:
struct S{
int a;
int b;
} s{ID().id, ID().id};
std::cout<<" Struct: "<<s.a<<", "<<s.b<<"\n";
yields Struct 1, 2
but it should be Struct 1, 1
- because the temporaries should be destructed at the end of the full-expression - in this case ID().id
.
Extended Description
Following this stackoverflow discussion http://stackoverflow.com/questions/39025342/lifetime-of-temporary-objects-during-list-initialization
The behaviour of clang differs from the behaviour of other compilers for this code:
The clang compiled program prints out
1, 2
, but programs produced by other compilers give1, 1
.Actually, I don't know what the right behaviour should be, but because other compilers seem to agree, I report the bug here.