0

プロジェクトで次の警告が表示されました (リリース モードとデバッグ モードの両方)。

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 が他のプロジェクトに含まれている場合、そのような警告は発行されません。

4

3 に答える 3

3

問題は、インライン化のためにコードがこれに変わることです。

_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

しかし、この時点で、警告はすでに発せられています。)

于 2012-04-20T20:39:03.500 に答える
1

おそらく、コンパイラはループを最適化していますが、static_cast. プログラムの関連部分のアセンブラ/ソース リストはありますか?

MSVC STL に関する私の経験では、コンパイルすると/W4多くの誤検知が発生します。

于 2012-04-20T18:18:47.153 に答える
1

このアプローチは機能します:

#pragma warning( disable : 4189 )
#include <concurrent_vector.h>
#pragma warning( default : 4189 )

皆さんありがとう

于 2012-04-25T17:39:47.400 に答える