https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92053
Bug ID: 92053 Summary: Compilation fails or succeeds depending on the optimization flags Product: gcc Version: 10.0 Status: UNCONFIRMED Keywords: accepts-invalid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: antoshkka at gmail dot com Target Milestone: --- Consider the following code: #include <utility> #include <memory> #include <variant> struct widget; using variant_t = std::variant<widget>; struct my_func { my_func(variant_t&& arg) { std::make_unique<variant_t>(std::move(arg)); } }; struct widget {}; my_func f({}); With `-std=c++2a -O0` it compiles. With `-std=c++2a -O2` it fails on a static assert in instantiation of 'struct std::is_default_constructible<widget>'. Godbolt playground: https://godbolt.org/z/-d26aG