Why doesn't GCC allow me to create `inline static std :: stringstream`?

I will go straight to MCVE:

#include <sstream>

struct A
{
    inline static std::stringstream ss;
};

GCC 7.2 and 7.1 refuse to compile with the following error:

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

You can reproduce this without any flags, as well as with -std=c++17.

Clang 5.0 compiles it without any problems.

Other classes (e.g. std::string) can be made inline staticwithout problems.

Troubleshoot using the built-in static file.

Is GCC a bug or am I missing something?

+4
source share
1 answer

Bug. Reduced to:

struct C { explicit C() {} };
struct A {
    inline static C c;
};

Something somewhere in the GCC initialization processing code incorrectly views this as a copy initialization context that the explicit default constructor ignored.

+4
source

Source: https://habr.com/ru/post/1690623/


All Articles