我有以下示例代码:
#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会发生这种情况.
感谢所有测试过的人!这似乎是铿锵的一个错误.如果有人向llvm.org报告,我会很感激.我的一些错误报告说,实际上并没有真正有用,所以我不打算重复这种经历.
| 归档时间: |
|
| 查看次数: |
748 次 |
| 最近记录: |