https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96645
Bug ID: 96645 Summary: std::variant default constructor Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: dev at hrookami dot icu Target Milestone: --- Appears in version 9 and above. Flags: -std=c++17 Code: #include <variant> void testVariant() { struct DataWithVariant { using Member = std::variant<int, float>; Member d; }; auto d = DataWithVariant{}; } void testVarStruct() { struct DataWithStruct { struct A { int number = 5; // compiles, if remove initialization }; struct B { bool flag = false; }; using Member = std::variant<A, B>; Member data; }; auto d = DataWithStruct{}; } int main() { testVariant(); testVarStruct(); } Compiler output: <source>: In function 'void testVarStruct()': <source>:26:29: error: use of deleted function 'std::variant<_Types>::variant() [with _Types = {testVarStruct()::DataWithStruct::A, testVarStruct()::DataWithStruct::B}]' 26 | auto d = DataWithStruct{}; | ^ In file included from <source>:1: /opt/compiler-explorer/gcc-9.1.0/include/c++/9.1.0/variant:1287:7: note: 'std::variant<_Types>::variant() [with _Types = {testVarStruct()::DataWithStruct::A, testVarStruct()::DataWithStruct::B}]' is implicitly deleted because the default definition would be ill-formed: 1287 | variant() = default; | ^~~~~~~ /opt/compiler-explorer/gcc-9.1.0/include/c++/9.1.0/variant:1287:7: error: use of deleted function 'constexpr std::_Enable_default_constructor<false, _Tag>::_Enable_default_constructor() [with _Tag = std::variant<testVarStruct()::DataWithStruct::A, testVarStruct()::DataWithStruct::B>]' In file included from /opt/compiler-explorer/gcc-9.1.0/include/c++/9.1.0/variant:38, from <source>:1: /opt/compiler-explorer/gcc-9.1.0/include/c++/9.1.0/bits/enable_special_members.h:110:15: note: declared here 110 | constexpr _Enable_default_constructor() noexcept = delete; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ It compiles if move nested structs in global namespace or remove initializer.