Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CppCoreChecker C-Style cast warning when using range based for loop on vector

Assume the following code:

#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;
    }
}

At the line of the for loop I get the following warning:

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

Can someone explain where this is coming from? Im using Visual Studio 2017 Community Edition Version 15.2.

like image 889
Maximilian Avatar asked Jun 27 '17 09:06

Maximilian


1 Answers

As seen in this bug report it seems to happen only for the std::string type when inserting into a basic_iostream. This bug has been resolved but hasn't been released yet so for now you'll just have to wait.

like image 196
Hatted Rooster Avatar answered Jan 27 '23 00:01

Hatted Rooster