user1235183
user1235183

Reputation: 3072

Avoid nasty warning C4100 in visual-studio

I'm using visual studio 2013 and get a lot of C4100 warnings in cases like this

void destroy(pointer p) {//warning C4100
     p->~T(); 
}

i don't understand why. My question how can i avoid this warning without #pragma warning (platform-independence, readability)?

Upvotes: 2

Views: 2123

Answers (1)

sergej
sergej

Reputation: 17999

This is a Visual Studio bug/limitation.

C4100 can also be issued when code calls a destructor on a otherwise unreferenced parameter of primitive type. This is a limitation of the Visual C++ compiler.

There should a be bug report, but I cant find it at the moment.

Workarounds:

  1. Reference p otherwise:

    void destroy(pointer p) {
        p;         //resolve warning C4100
        p->~T(); 
    }
    
  2. Disable the warning:

    • compile without /W4 or
    • compile with /wd4100 or
    • add #pragma warning(disable : 4100)
  3. Use another compiler.

Upvotes: 4

Related Questions