有没有办法禁用 std 标头的 VS 智能感知警告,而无需用垃圾包装每个包含

Is there a way to disable VS intellisense warnings for std headers without wrapping every include with garbage

提问人:Lake 提问时间:4/5/2021 更新时间:4/6/2021 访问量:1364

问:

Visual Studio 的智能感知生成以下警告:

Severity    Code    Description Project File    Line    Suppression State
Warning C26495  Variable 'std::exception_ptr::_Data1' is uninitialized. Always initialize a member variable (type.6).   MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\exception   216 
Warning C26495  Variable 'std::exception_ptr::_Data2' is uninitialized. Always initialize a member variable (type.6).   MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\exception   216 
Warning C26495  Variable 'std::exception_ptr::_Data1' is uninitialized. Always initialize a member variable (type.6).   MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\exception   220 
Warning C26495  Variable 'std::exception_ptr::_Data2' is uninitialized. Always initialize a member variable (type.6).   MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\exception   220 
Warning C26495  Variable 'std::exception_ptr::_Data1' is uninitialized. Always initialize a member variable (type.6).   MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\exception   228 
Warning C26495  Variable 'std::exception_ptr::_Data2' is uninitialized. Always initialize a member variable (type.6).   MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\exception   228 
Warning C26439  This kind of function may not throw. Declare it 'noexcept' (f.6).   MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\map 144 
Warning C26495  Variable 'std::error_category::_Addr' is uninitialized. Always initialize a member variable (type.6).   MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\system_error    70  
Warning C26439  This kind of function may not throw. Declare it 'noexcept' (f.6).   MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\unordered_map   200 
Warning C26439  This kind of function may not throw. Declare it 'noexcept' (f.6).   MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xhash   413 
Warning C26439  This kind of function may not throw. Declare it 'noexcept' (f.6).   MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xhash   577 
Warning C26495  Variable 'std::ios_base::_Except' is uninitialized. Always initialize a member variable (type.6).   MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xiosbase    460 
Warning C26495  Variable 'std::ios_base::_Fmtfl' is uninitialized. Always initialize a member variable (type.6).    MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xiosbase    460 
Warning C26495  Variable 'std::ios_base::_Mystate' is uninitialized. Always initialize a member variable (type.6).  MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xiosbase    460 
Warning C26495  Variable 'std::ios_base::_Prec' is uninitialized. Always initialize a member variable (type.6). MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xiosbase    460 
Warning C26495  Variable 'std::ios_base::_Wide' is uninitialized. Always initialize a member variable (type.6). MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xiosbase    460 
Warning C26495  Variable 'std::locale::_Ptr' is uninitialized. Always initialize a member variable (type.6).    MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xlocale 265 
Warning C26451  Arithmetic overflow: Using operator '+' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '+' to avoid overflow (io.2). MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xlocale 963 
Warning C26451  Arithmetic overflow: Using operator '-' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '-' to avoid overflow (io.2). MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xlocale 963 
Warning C26451  Arithmetic overflow: Using operator '+' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '+' to avoid overflow (io.2). MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xlocale 1074    
Warning C26451  Arithmetic overflow: Using operator '+' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '+' to avoid overflow (io.2). MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xlocale 1246    
Warning C26451  Arithmetic overflow: Using operator '+' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '+' to avoid overflow (io.2). MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xlocale 1321    
Warning C26451  Arithmetic overflow: Using operator '+' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator '+' to avoid overflow (io.2). MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xlocale 1332    
Warning C26819  Unannotated fallthrough between switch labels (es.78).  MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xlocale 2014    
Warning C26819  Unannotated fallthrough between switch labels (es.78).  MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xlocale 2215    
Warning C26495  Variable 'std::_String_val<std::_Simple_types<char16_t> >::_Bxty::_Alias' is uninitialized. Always initialize a member variable (type.6).   MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xstring 2252    
Warning C26495  Variable 'std::_String_val<std::_Simple_types<char16_t> >::_Bxty::_Buf' is uninitialized. Always initialize a member variable (type.6). MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xstring 2252    
Warning C26495  Variable 'std::_String_val<std::_Simple_types<char16_t> >::_Bxty::_Ptr' is uninitialized. Always initialize a member variable (type.6). MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xstring 2252    
Warning C26495  Variable 'std::_String_val<std::_Simple_types<char32_t> >::_Bxty::_Alias' is uninitialized. Always initialize a member variable (type.6).   MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xstring 2252    
Warning C26495  Variable 'std::_String_val<std::_Simple_types<char32_t> >::_Bxty::_Buf' is uninitialized. Always initialize a member variable (type.6). MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xstring 2252    
Warning C26495  Variable 'std::_String_val<std::_Simple_types<char32_t> >::_Bxty::_Ptr' is uninitialized. Always initialize a member variable (type.6). MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xstring 2252    
Warning C26495  Variable 'std::_String_val<std::_Simple_types<char> >::_Bxty::_Alias' is uninitialized. Always initialize a member variable (type.6).   MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xstring 2252    
Warning C26495  Variable 'std::_String_val<std::_Simple_types<char> >::_Bxty::_Buf' is uninitialized. Always initialize a member variable (type.6). MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xstring 2252    
Warning C26495  Variable 'std::_String_val<std::_Simple_types<char> >::_Bxty::_Ptr' is uninitialized. Always initialize a member variable (type.6). MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xstring 2252    
Warning C26495  Variable 'std::_String_val<std::_Simple_types<wchar_t> >::_Bxty::_Alias' is uninitialized. Always initialize a member variable (type.6).    MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xstring 2252    
Warning C26495  Variable 'std::_String_val<std::_Simple_types<wchar_t> >::_Bxty::_Buf' is uninitialized. Always initialize a member variable (type.6).  MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xstring 2252    
Warning C26495  Variable 'std::_String_val<std::_Simple_types<wchar_t> >::_Bxty::_Ptr' is uninitialized. Always initialize a member variable (type.6).  MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xstring 2252    
Warning C26439  This kind of function may not throw. Declare it 'noexcept' (f.6).   MD  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\xtree   907 

我显然不希望显示来自 std 标头的警告。 我想出了一个非常丑陋的解决方法,包括将每个 std 包含在整个项目中,如下所示:

#include <CodeAnalysis/Warnings.h>
#pragma warning(push)
#pragma warning(disable: ALL_CODE_ANALYSIS_WARNINGS)
#include <vector>
#pragma warning(pop)

这看起来像垃圾,完全没有意义。 有没有一种简单有效的方法可以告诉 intellisense 忽略 std 标头的警告,或者至少使上述内容更漂亮?

C++ Visual-Studio 警告 IntelliSense

评论


答:

0赞 Sara Liu - MSFT 4/6/2021 #1

您可以尝试关闭“项目属性设置”下的所有警告。

右键单击您的项目 属性-->配置 属性-->C/C++-->常规

“警告级别”更改为Turn Off All Warnings(/W0)

或者,如果您不想禁用所有警告,而只想禁用这些显示的特定警告,则可以尝试以下操作:

项目属性-->配置属性-->C/C++-->高级-->在禁用特定警告中键入以下内容:

26495;26439;26451;26819

我只找到了这些,这些方法不会让你单独抑制每个文件中的代码。cpp

评论

0赞 Lake 4/6/2021
是的,我知道这一点,不幸的是,关闭标准库标头中发生的所有警告类型是有害的,因为相同的警告也可能发生在我的代码中,我希望^^报告 好吧,我想除了用垃圾包装包含之外别无他法。
0赞 Sara Liu - MSFT 4/6/2021
确定。禁止显示所有警告不是一个好的选择。因此,您可以禁止显示项目中的相关特定警告。它不会中断其他类型的警告的显示。使用这个会对你有所帮助。让我们知道这是否对您有所帮助。
3赞 Lake 4/6/2021
只是为了明确我的观点:我不想关闭,比如说 26495,因为我确实希望它在我的代码中报告未初始化的成员。尽管如此,当它发生在标准库头文件中时,我并不关心同样的警告(因为我没有编写它们)。因此,我无法通过禁用特定警告来解决我的问题。