gpt4 book ai didi

c++ - concurrent_vector.h 中的警告 C4189

转载 作者:太空宇宙 更新时间:2023-11-04 16:27:47 25 4
gpt4 key购买 nike

我在我的项目(发布和 Debug模式)中收到以下警告:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\concurrent_vector.h(1599): warning C4189: '_Array' : local variable is initialized but not referenced
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\concurrent_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_path\somefile.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

但此时警告已经发出。)

关于c++ - concurrent_vector.h 中的警告 C4189,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10251152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com