Ich werde direkt zum MCVE gehen:Warum GCC mir nicht erlaubt, `inline statisch std :: stringstream` zu erstellen?
#include <sstream>
struct A
{
inline static std::stringstream ss;
};
GCC 7.2 und 7.1 refuse to compile es mit folgenden Fehlern:
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
Sie, dass ohne Fahnen reproduzieren kann, sowie mit -std=c++17
.
Clang 5.0 kompiliert es ohne Probleme.
Andere Klassen (zB std::string
) können ohne Probleme inline static
gemacht werden.
Wenn Sie es nicht inline statisch machen, wird der Fehler entfernt.
Ist ein GCC Bug oder fehlt mir etwas?
Welche Compiler-Optionen verwenden Sie? IIRC, Inline-Variablen werden für C++ 17 vorgeschlagen. Benötigt die Version von GCC, die Sie verwenden, etwas wie '-std = C++ 17'? –
@AndrewHenle Es funktioniert nicht mit oder ohne '-std = C++ 17 ', keine anderen Flags sind erforderlich, um zu reproduzieren. Wie gesagt, inline statische Variable anderer Typen funktionieren gut. – HolyBlackCat
Mögliche Abhilfe: 'static inline std :: stringstream ss {};'? –