【发布时间】:2016-09-05 05:09:59
【问题描述】:
我有一些简单的 C++ 代码,它们不会被 C++ Builder 10.1 Berlin 的基于 Clang 的 C++11 编译器 bccaarm 编译。
这是代码:
TComponent* Comp = new TComponent(this);
std::vector<TComponent*> Comps;
Comps.push_back(Comp);
这是错误:
[bccaarm 错误] stl_iterator.h(963): 对类型的右值引用 'value_type' (aka 'System: classes::TComponent * __strong') 不能 绑定到“__borland_class * isTObj __strong”类型的左值(又名 'System::Classes::TComponent * __strong')
编译器在文件 stl_iterator.h 的第 963 行停止:
其他 C++ 编译器 bcc32 和 bcc32c(也基于 Clang)对此代码没有问题。
当Comp不是来自TComponent类型或TObject的另一个后代时,代码编译没有任何问题。
我不知道这段代码有什么问题,也不知道为什么 R 和 L 值有问题...
有人知道在这里做什么吗?
【问题讨论】:
-
英文翻译是这样的:
[bccaarm error] stl_iterator.h(963): rvalue reference to type 'value_type' (aka 'System: classes::TComponent * __strong') can not be bound to lvalue of type '__borland_class * isTObj __strong' (aka 'System::Classes::TComponent * __strong')移动编译器,如 bccaarm,实现 Object ARC(这就是__strong发挥作用的地方),但桌面编译器没有,这就是代码在 bcc32 和 bcc32c 中编译的原因。 -
我希望这段代码在 ARC 下编译得很好,虽然我觉得
std::vector::iterator::operator*使用std::move()很奇怪。运算符应该返回对向量中现有项目的引用,不应该涉及移动。也许是一个 STL 错误? -
@RemyLebeau:添加 __unsafe 有帮助(请参阅答案),但仍不清楚 STL 中是否存在错误...
标签: android c++ c++builder firemonkey c++builder-10.1-berlin