为什么clang ++只会破坏一个foo对象?

won*_*bie 51 c++ clang

我有以下示例代码:

#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;
}
Run Code Online (Sandbox Code Playgroud)

当我用clang ++ -std = c ++ 11 test.cc编译它时,程序产生以下输出:

foo constructed.
foo constructed.
foo destroyed.
Run Code Online (Sandbox Code Playgroud)

但我预计还有一个"foo被摧毁".介于两个"foo构造"之间.线.为什么只有一个foo被摧毁?clang 3.5.1以及3.6.0会发生这种情况.

won*_*bie 7

感谢所有测试过的人!这似乎是铿锵的一个错误.如果有人向llvm.org报告,我会很感激.我的一些错误报告说,实际上并没有真正有用,所以我不打算重复这种经历.

  • 完成https://llvm.org/bugs/show_bug.cgi?id=22877(包括将其转换为与asan和valgrind一起显示的内存泄漏) (14认同)