c++ - 有没有办法禁用 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)
这看起来像垃圾,完全没有意义。有没有一种简单有效的方法来告诉智能感知忽略标准头的警告,或者至少使上述更漂亮?
解决方案
您可以尝试关闭Project Properties Settings下的所有警告。
右键单击您的项目属性-->配置属性--> C/C++ -->常规
将警告级别更改为Turn Off All Warnings(/W0)
或者,如果您不想禁用所有警告而只显示这些特定警告,您可以尝试以下方法:
项目属性-->配置属性--> C/C++ -->高级--> 将这些输入禁用特定警告:
26495;26439;26451;26819
我只发现了这些,这些方法不会让你cpp
单独抑制每个文件中的代码。
推荐阅读
- java - kotlin 中的 supportFragmentManager.commit 不起作用
- php - 雄辩的查询没有返回预期的结果
- python-3.x - 为分类变量的每个级别创建新的数据框(Pandas)
- java - 如何在不将其作为方法参数传递的情况下向 POJO 类提供转换器服务
- spring - 即使 OAuth2 验证失败,如何记录 http 请求/响应正文?
- html - 导航栏下划线悬停动画
- c# - 使用正则表达式 C# 搜索单词或类似单词
- amazon-eks - 如何在两个 EKS 服务之间共享 AWS NLB?
- java - 为什么 Maven 要使用 javax.persistence 而不是替代的休眠版本
- oracle - 无法在 SQL CREATE TABLE 命令中设置 INTEGER 数据类型的精度