2011-08-30 19 views
2

我正在編譯/ Wall,並且收到警告C4100: 'ptr' : unreferenced formal parameter warning。警告似乎是通過調用MSVC的std::_Container_proxy上的析構函數引起的,該函數具有默認的析構函數。是POD靜態的默認析構函數嗎?

我的代碼:

template<class T> 
class linear_allocator { 
    //...other declarations... 
    static void destroy(pointer ptr); 
}; 
//...other definitions... 
template<class T> 
inline void linear_allocator<T>::destroy(typename linear_allocator<T>::pointer ptr) 
{ 
    ptr->~T(); //line 262. warning C4100: 'ptr' : unreferenced formal parameter 
} 
//ironically, this isn't a test case, this is my actual thingy class. Go figure. 
struct thingy { 
    unsigned int DATA; 
    thingy() : DATA(0xABCDEF) {} 
    ~thingy() {assert(DATA == 0xABCDEF);} 
}; 
int main() { 
    typedef std::vector<thingy, linear_allocator<thingy>> thingyholder; 
    std::vector<thingyholder> holder; 
} 

警告的全文是:

 f:\code\utilities\linear_allocator\linear_allocator.h(261): warning C4100: 'ptr' : unreferenced formal parameter 
     f:\code\utilities\linear_allocator\linear_allocator.h(262) : while compiling class template member function 'void linear_allocator<T>::destroy(std::_Container_proxy *)' 
     with 
     [ 
      T=std::_Container_proxy 
     ] 
     f:\code\utilities\linear_allocator\linear_allocator.h(178) : while compiling class template member function 'linear_allocator<T>::~linear_allocator(void) throw()' 
     with 
     [ 
      T=std::_Container_proxy 
     ] 
     c:\program files\microsoft visual studio 10.0\vc\include\vector(454) : see reference to class template instantiation 'linear_allocator<T>' being compiled 
     with 
     [ 
      T=std::_Container_proxy 
     ] 
     c:\program files\microsoft visual studio 10.0\vc\include\vector(452) : while compiling class template member function 'std::_Vector_val<_Ty,_Alloc>::~_Vector_val(void)' 
     with 
     [ 
      _Ty=thingy, 
      _Alloc=linear_allocator<thingy> 
     ] 
     c:\program files\microsoft visual studio 10.0\vc\include\vector(481) : see reference to class template instantiation 'std::_Vector_val<_Ty,_Alloc>' being compiled 
     with 
     [ 
      _Ty=thingy, 
      _Alloc=linear_allocator<thingy> 
     ] 
     c:\program files\microsoft visual studio 10.0\vc\include\vector(1307) : see reference to class template instantiation 'std::vector<_Ty,_Ax>' being compiled 
     with 
     [ 
      _Ty=thingy, 
      _Ax=linear_allocator<thingy> 
     ] 
     c:\program files\microsoft visual studio 10.0\vc\include\vector(1301) : while compiling class template member function 'void std::vector<_Ty>::_Tidy(void)' 
     with 
     [ 
      _Ty=thingyholder 
     ] 
     f:\code\utilities\linear_allocator\main.cpp(71) : see reference to class template instantiation 'std::vector<_Ty>' being compiled 
     with 
     [ 
      _Ty=thingyholder 
     ] 

我看到它使用的std::_Container_proxy析構函數,這簡直是:

struct _Container_proxy 
{ // store head of iterator chain and back pointer 
_Container_proxy() 
    : _Mycont(0), _Myfirstiter(0) 
    { // construct from pointers 
    } 

const _Container_base12 *_Mycont; 
_Iterator_base12 *_Myfirstiter; 
}; 

根據MSVC C4100: 'application' : unreferenced formal parameter warning,這可能發生if The functions you are calling using the application object are static functions, so they aren't really referencing the application object.std::_Container_proxy似乎是一個POD,這是否意味着默認析構函數作爲一個優化是靜態的?

(是的,我知道不同的解決方法,使警告消失我想知道爲什麼我得到警告我把ptr=ptr; //warning workaround前。)

+0

它是「析構函數」。 –

+0

我幾乎在每個地方都寫了一個構造函數,讓自己感到困惑。 –

+0

在我的代碼工作中,我在音頻「propmts」的評論中有很多引用。 –

回答