简体   繁体   English

静态std :: stringstream的clang-tidy警告

[英]Clang-tidy warning for static std::stringstream

I have the following MCVE: 我有以下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: 当我在这段代码上运行clang-tidy 6.0.1时,我得到以下警告:

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 . 似乎问题在于std::stringstream的构造函数有一个默认值为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? 如果是这样,在类中使用静态std::stringstream的正确方法是什么?

MSVC 2015(windows) compiles the above code snippet without any warnings. MSVC 2015(windows)编译上面的代码片段,没有任何警告。 Verified the headers and it has constexpr. 验证了标题,它有constexpr。 Looks like an issue with Clang-tidy. 看起来像Clang-tidy的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM