https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93034
Bug ID: 93034 Summary: variant not constexpr in c++17 mode Product: gcc Version: 7.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: rene.r...@fu-berlin.de Target Milestone: --- Hi there, I couldn't find a related issue but maybe I just missed it. But it seems that the copy and move constructor of std::variant are not declared constexpr for gcc-7. ``` #include <variant> using variant_t = std::variant<int>; inline constexpr variant_t v1{}; // OK inline constexpr variant_t v2{v1}; // Error inline constexpr variant_t v3{std::move(v1)}; // Error inline constexpr variant_t v4{3}; // OK ``` Here is the corresponding error: ``` <source>:6:33: error: call to non-constexpr function 'std::variant<_Types>::variant(const std::variant<_Types>&) [with _Types = {int}]' inline constexpr variant_t v2{v1}; // Error ^ In file included from <source>:1:0: /opt/compiler-explorer/gcc-7.5.0/include/c++/7.5.0/variant:943:7: note: 'std::variant<_Types>::variant(const std::variant<_Types>&) [with _Types = {int}]' is not usable as a constexpr function because: variant(const variant&) = default; ^~~~~~~ /opt/compiler-explorer/gcc-7.5.0/include/c++/7.5.0/variant:407:7: note: defaulted constructor calls non-constexpr 'std::__detail::__variant::_Variant_base<_Types>::_Variant_base(const std::__detail::__variant::_Variant_base<_Types>&) [with _Types = {int}]' _Variant_base(const _Variant_base& __rhs) ^~~~~~~~~~~~~ <source>:7:44: error: call to non-constexpr function 'std::variant<_Types>::variant(const std::variant<_Types>&) [with _Types = {int}]' inline constexpr variant_t v3{std::move(v1)}; // Error ^ Compiler returned: 1 ``` This compiles fine with g++8 and g++9 and trunk. Compiled on the compiler explorer using g++-7.5 with flags: -std=c++17 -Wall -Wextra -pedantic Any help in finding a solution for this would be really appreciated.