对于我的编译器测试,我需要在测试代码中生成此警告“声明无效”。我怎样才能做到这一点?

使用VS cl.exe编译器

最佳答案

int main()
{
    5;   // Statement has no effect
    return 0;
}

编辑1 在VC++ 2010上尝试
#include <iostream>
#pragma warning(default:4555)

int main()
{
    5;
    getchar();
    return 0;
}

输出:
warning C4555:main.cpp(6): expression has no effect; expected expression with side-effect
注意:似乎VC++ 2010在其列表上没有C4705警告。 MSDN Compiler Warnings

07-24 09:45
查看更多