首页 > 解决方案 > 有没有办法禁用 VS intellisense 对 std 标头的警告,而不用垃圾包装每个包含

问题描述

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)

这看起来像垃圾,完全没有意义。有没有一种简单有效的方法来告诉智能感知忽略标准头的警告,或者至少使上述更漂亮?

标签: c++visual-studiowarningsintellisense

解决方案


您可以尝试关闭Project Properties Settings下的所有警告。

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

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

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

项目属性-->配置属性--> C/C++ -->高级--> 将这些输入禁用特定警告

26495;26439;26451;26819

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


推荐阅读