https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96999
Bug ID: 96999 Summary: regression: std::variant requires default constructor with gcc 8-9, gcc 7.x and 10.x works Product: gcc Version: 9.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dushistov at mail dot ru Target Milestone: --- For code bellow, gcc 9.3 from Ubuntu reports error: ``` In file included from /usr/include/c++/9/variant:36, from test.cpp:1: ... /usr/include/c++/9/type_traits:931:47: error: ‘Foo::Foo()’ is private within this context 931 | : public integral_constant<bool, noexcept(_Tp())> | ^~~~~ test.cpp:10:3: note: declared private here 10 | Foo() noexcept {} | ^~~ ``` gcc 8.x also reports error. gcc 7.x and 10.x works just fine: ``` #include <variant> #include <string> struct Foo { public: explicit Foo(int) noexcept {} Foo(Foo &&) noexcept = default; Foo &operator=(Foo &&) = default; private: Foo() noexcept {} }; struct Boo { public: explicit Boo(int) noexcept {} Boo(Boo &&) noexcept = default; Boo &operator=(Boo &&) = default; private: Boo() noexcept {} }; template<bool X> std::variant<Foo, Boo> g(int v, int x) { return v == 0 ? std::variant<Foo, Boo>{Foo{x}} : std::variant<Foo, Boo>{Boo{x}}; } int main() { std::variant<std::variant<Foo, Boo>, std::string> err{std::string("aaa")}; } ```