Clang-tidy warning for static std::stringstream

Viewed 581

I have the following MCVE:

#include <sstream>

struct A {
    static std::stringstream s;
};

std::stringstream A::s;

int main() {}

When I run clang-tidy 6.0.1 on this code I get the following warning:

static_sstream.cpp:7:22: warning: initializing non-local variable with non-const expression depending on uninitialized non-local variable 'out' [cppcoreguidelines-interfaces-global-init]
std::stringstream A::s;
                     ^

It seems that the problem lies in the fact that the constructor of std::stringstream has a parameter with the default value of std::ios_base::out. My question is, is this a real problem? And if so, what is the correct way of using a static std::stringstream in a class?

1 Answers

MSVC 2015(windows) compiles the above code snippet without any warnings. Verified the headers and it has constexpr. Looks like an issue with Clang-tidy.

Related