避免在 visual-studio 中出现讨厌的警告 C4100

Avoid nasty warning C4100 in visual-studio

我正在使用 visual studio 2013,在这种情况下收到很多 C4100 警告

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

我不明白为什么。我的问题是如何在没有#pragma 警告(平台独立性、可读性)的情况下避免此警告?

这是一个Visual Studiobug/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.

应该有错误报告,但我暂时找不到。

解决方法:

  1. 参考p否则:

    void destroy(pointer p) {
        p;         //resolve warning C4100
        p->~T(); 
    }
    
  2. 禁用警告:

    • 在没有 /W4
    • 的情况下编译
    • /wd4100
    • 编译
    • 添加#pragma warning(disable : 4100)
  3. 使用其他编译器。