cpp:S6009 false positive with wstring const reference

Using SonarLint for Visual Studio 4.35.0.32570

I define a method as this:

inline void WriteCsv(const CsvData& input, const std::wstring& filename, wchar_t delimiter)
    {
        std::wofstream myfile;
        std::wstring a;

        myfile.open(filename);

        myfile << L"sep=" << delimiter << L"\n";

        for (auto i = input.begin(); i != input.end(); ++i)
        {
            for (auto j = i->begin(); j != i->end(); ++j)
            {
                a = *j;
                myfile << a << delimiter;

            }
            myfile << "\n";
        }
        myfile.close();
    }

And I get a false positive on the filename parameter. If I fix the suggestion, I get an error on open that requests an explicit const ref wstring.

the same happens with an overload, so it’s not only with std methods:

    inline void WriteCsv(const CsvData& input, const std::wstring& filename)
    {
        WriteCsv(input, filename, ';');
    }

The solution here applies: cpp:S995 false positive with wistream reference - #6 by Amelie

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.