【发布时间】:2018-05-26 10:48:18
【问题描述】:
我会直接去 MCVE:
#include <sstream>
struct A
{
inline static std::stringstream ss;
};
GCC 7.2 和 7.1 refuse to compile 出现以下错误:
错误:没有匹配函数调用 '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] basic_stringstream(basic_stringstream&& __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 错误还是我遗漏了什么?
【问题讨论】:
-
您使用什么编译器选项? IIRC,
inline变量是针对 C++17 提出的。您使用的 GCC 版本是否需要-std=c++17之类的内容? -
@AndrewHenle 无论有没有
-std=c++17,它都不起作用,不需要其他标志来重现。正如我所说,其他类型的内联静态变量工作正常。 -
可能的解决方法:
static inline std::stringstream ss{};? -
@AndrewHenle C++17 已经发布
标签: c++ gcc stringstream