Why does clang ++ destroy only one foo object?

I have the following code example:

#include <iostream> using namespace std; struct foo { foo() { cout << "foo constructed.\n"; } ~foo() { cout << "foo destroyed.\n"; } }; struct bar { bar(foo t=foo{}) { } }; int main(int argc, char **argv) { bar X[2]{}; return 0; } 

When I compile it with clang ++ -std = C ++ 11 test.cc, the program produces the following output:

 foo constructed. foo constructed. foo destroyed. 

but I was expecting an additional "foo destroy". between two "foo built". lines. Why is only one foo destroyed? This happens with clang 3.5.1 as well as 3.6.0.

+51
c ++ clang
Mar 11 '15 at 15:40
source share
1 answer

Thanks to everyone who tested it! This seems to be a bug in clang. I would be grateful if anyone reports this on llvm.org. My small error messages were, say, not very useful, so I do not want to repeat this experience.

+7
Mar 11 '15 at 22:00
source share



All Articles