4
私はMCVEにまっすぐに行くよ:なぜGCCでは `inline static std :: stringstream`を作成できないのですか?
#include <sstream>
struct A
{
inline static std::stringstream ss;
};
GCC 7.2と7.1 refuse to compileそれが次のエラーで:
error: no matching function for call to 'std::__cxx11::basic_stringstream::basic_stringstream()' inline static std::stringstream ss; ^~ In file included from blah:1:0: /opt/compiler-explorer/gcc-7.2.0/include/c++/7.2.0/sstream:723:7: note: candidate: std::__cxx11::basic_stringstream::basic_stringstream(std::__cxx11::basic_stringstream&&) [with _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: note: candidate expects 1 argument, 0 provided
あなたが任意のフラグなしでそれを再現するだけでなく、-std=c++17
とすることができます。
Clang 5.0は問題なくコンパイルします。
他のクラス(例:std::string
)を問題なく作成することができます。inline static
非インライン静的にするとエラーが取り除かれます。
GCCのバグではないのですか、何か不足していますか?
あなたはどのようなコンパイラオプションを使用している:まで減少? IIRCでは、 'inline'変数がC++で提案されています。あなたが使っているGCCのバージョンは '-std = C++ 17'のようなものが必要ですか? –
@AndrewHenle '-std = C++ 17'の有無にかかわらず動作しません。再現するために他のフラグは必要ありません。私が言ったように、他の型のインライン静的変数は正常に動作します。 – HolyBlackCat
考えられる回避策: 'static inline std :: stringstream ss {};'? –