警告 C4189 在 concurrent_vector.h 中
warning C4189 in concurrent_vector.h
我在项目中收到以下警告(发布和调试模式):
C:Program Files (x86)Microsoft Visual Studio 10.0VCincludeconcurrent_vector.h(1599): warning C4189: '_Array' : local variable is initialized but not referenced
C:Program Files (x86)Microsoft Visual Studio 10.0VCincludeconcurrent_vector.h(1598) : while compiling class template member function 'void Concurrency::concurrent_vector<_Ty>::_Destroy_array(void *,Concurrency::concurrent_vector<_Ty>::size_type)'
with
[
_Ty=Vector3i
]
d:Some_pathsomefile.h(780) : see reference to class template instantiation 'Concurrency::concurrent_vector<_Ty>' being compiled
with
[
_Ty=Vector3i
]
其中somefile.h是我的文件,第780行有以下代码:
Concurrency::concurrent_vector<Vector3i> m_ovColors;
Vector3i是这样的:
template<typename T> class TVector3 {
public:
T x, y, z;
}
typedef TVector3<int> Vector3i;
concurrent_vector.h 中第 1598 行周围的代码是(第 1598 行只是"{"):
template<typename _Ty, class _Ax>
void concurrent_vector<_Ty, _Ax>::_Destroy_array( void* _Begin, size_type _N )
{
_Ty* _Array = static_cast<_Ty*>(_Begin);
for( size_type _J=_N; _J>0; --_J )
_Array[_J-1].~_Ty(); // destructors are supposed to not throw any exceptions
}
这其中可能是什么原因?这个 somefile.h 包含在其他项目中时不会发出这种警告。
问题是代码由于内联而变成这样:
_Ty* _Array = static_cast<_Ty*>(_Begin);
for( size_type _J=_N; _J>0; --_J )
; // destructor has no effect!
此时,编译器将停止并检查是否使用了所有初始化的变量,并发出该警告。
(然后代码将被优化为空函数:
; // variable is unused
; // loop has no effect
但此时警告已经发出
也许编译器正在优化循环而不是static_cast
。 您是否有程序相关部分的汇编程序/源代码列表?
我对 MSVC STL 的经验是,如果使用/W4
进行编译,则会得到很多误报。
此方法有效:
#pragma warning( disable : 4189 )
#include <concurrent_vector.h>
#pragma warning( default : 4189 )
谢谢大家
相关文章:
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 在c++中用vector填充一个简单的动态数组
- vector.resize()中的分配错误
- 使用std::vector的OpenCL矩阵乘法
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 在某些循环内使用vector.push_back时出现分段错误
- 当vector是tje全局变量时,c++中vector的内存管理
- std::vector的包装器,使数组的结构看起来像结构的数组
- 为什么(-1)%vector::size()总是返回0
- 在C++中将类(带有Vector成员)保存为二进制文件
- 编译器如何区分std::vector的构造函数
- 将 int 数组转换为 std::vector<int*>
- 使用 pqxx 将 std::vector 存储在 postgresql 中,并从数据库中检索它
- 在std::vector上存储带有模板的类实例
- 在main()之外初始化std::vector会导致性能下降(多线程)
- 为什么std::vector比数组慢
- std::vector::迭代器是否可以合法地作为指针
- 如何将二进制格式的 C++ 对象的 std::vector 保存到磁盘?
- 循环中的条件:为什么每次都调用strlen(),而vector.size()只调用一次
- 为什么std::vector和std::valarray初始化构造函数不同