Hol*_*Cat 4 c++ gcc stringstream
我会直接去 MCVE:
#include <sstream>
struct A
{
inline static std::stringstream ss;
};
Run Code Online (Sandbox Code Playgroud)
GCC 7.2 和 7.1拒绝编译它并出现以下错误:
错误:没有用于调用“std::__cxx11::basic_stringstream::basic_stringstream()”的匹配函数
内联静态 std::stringstream ss;
^~
在 blah:1:0 包含的文件中:
/opt/compiler-explorer/gcc-7.2.0/include/c++/7.2.0/sstream:723:7:注意:候选:std::__cxx11::basic_stringstream::basic_stringstream(std::__cxx11::basic_stringstream&&) [与_CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]
基本字符串流(基本字符串流&& __rhs)
^~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-7.2.0/include/c++/7.2.0/sstream:723:7: 注意:候选需要 1 个参数,提供 0
您可以在没有任何标志的情况下重现它,也可以使用-std=c++17.
Clang 5.0 编译它没有任何问题。
其他类(例如std::string)可以inline static毫无问题地制作。
使其成为非内联静态消除错误。
不是 GCC 错误还是我遗漏了什么?
漏洞。缩减为:
struct C { explicit C() {} };
struct A {
inline static C c;
};
Run Code Online (Sandbox Code Playgroud)
GCC 初始化处理代码中的某处错误地将其视为忽略显式默认构造函数的复制初始化上下文。