c++ - 在 vector 上使用基于范围的 for 循环时,CppCoreChecker C 样式转换警告

标签 c++ c++11 static-analysis cpp-core-guidelines

假设以下代码:

#include <iostream>
#include <vector>
#include <string>

int main() {
    std::vector<std::string> lines;
    lines.push_back("line");
    for (const auto& s : lines) {
        std::cout << s;
    }
}

在 for 循环的那一行,我收到以下警告:

C26493 Don't use C-style casts that would perform a static_cast downcast, const_cast, or reinterpret_cast.

谁能解释一下这是从哪里来的?我正在使用 Visual Studio 2017 Community Edition 版本 15.2。

最佳答案

this bug report 所示当插入到 basic_iostream 中时,它似乎只发生在 std::string 类型上。此错误已解决,但尚未发布,所以现在您只能等待。

关于c++ - 在 vector 上使用基于范围的 for 循环时,CppCoreChecker C 样式转换警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44776507/

相关文章:

c++ - <unresolved overloaded function type> 尝试将聚合对象的方法传递给其类方法时

c++11 - 数据与 memcpy 的 std::shared_ptr 分配

c++ - 从 C++ 中的 std::chrono::time_point 中提取年/月/日等

c++ - 为什么我们需要第二个 std::forward 特化?

static-analysis - terraform 的静态代码分析工具

c++ - QT_TR_NOOP : translation files are generated, 但从未使用过翻译后的字符串,为什么?

c++ - 在 BGL 中恢复 A 星搜索

c++ - 简单的 boost 智能指针语法问题

c# - 如何执行空检查?

python - 查找函数输出的输入依赖关系