clang-tidy's bugprone-exception-escape behaves weirdly with MSVC STL

Viewed 898

I'm using clang-tidy 10 on a project and it's behaving weirdly on Windows with the MSVC STL. A minimal example is the following:

#include <iostream>
#include <stdexcept>

int main()
{
    try {
        throw std::runtime_error {"Boom!"};
    } catch (...) {
        std::cerr << "Unexpected non-exception error!\n";
    }
}

If I tell it to include the check bugprone-exception-escape, it tells me an exception may be thrown in function 'main'. However, if I change the line streaming to std::cerr with the following then the check does not cause a complaint:

std::cerr << "Unexpected non-exception error!\n" << std::flush;

I assume the two consecutive stream operations on one line is the cause of the problem, because the following does raise the problem.

std::cerr << "Unexpected non-exception error!\n";
std::cerr << std::flush;

I noticed clang-tidy does not complain on any of these examples on Linux, at least if I pass -stdlib=libc++. Is there some weird subtlety I'm missing, or is this a bug in clang-tidy and/or MSVC's STL implementation?

0 Answers
Related