https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106067
Bug ID: 106067 Summary: Error on implicit conversion to std::function: 'static constexpr bool std::_Function_handler<...>...' used before its definition Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: e.tadeu at gmail dot com Target Milestone: --- The following code started failing on GCC 11.3 (also fails on GCC 12): #include <functional> double fn(); template <double (*T)(std::function<double()>)> void caller() { auto f = T(fn); // auto f = T(std::function<double()>(fn)); // workaround (this works) } The snippet is also here: https://godbolt.org/z/zh7nr7vKc The full error is: In file included from /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/move.h:57, from /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/stl_function.h:60, from /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/functional:49, from <source>:1: /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/type_traits: In instantiation of 'struct std::is_trivially_copyable<double (*)()>': /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/std_function.h:69:12: required from 'struct std::__is_location_invariant<double (*)()>' /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/std_function.h:125:38: required from 'const bool std::_Function_base::_Base_manager<double (*)()>::__stored_locally' /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/std_function.h:130:8: required from 'class std::_Function_base::_Base_manager<double (*)()>' /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/std_function.h:260:11: required from 'class std::_Function_handler<double(), double (*)()>' /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/std_function.h:436:65: required from 'std::function<_Res(_ArgTypes ...)>::function(_Functor&&) [with _Functor = double (*)(); _Constraints = void; _Res = double; _ArgTypes = {}]' <source>:8:15: required from here /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/type_traits:713:52: error: non-constant condition for static assertion 713 | static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/type_traits:713:52: error: 'constexpr std::true_type std::__is_complete_or_unbounded(std::__type_identity<_Tp>) [with _Tp = double (*)(); long unsigned int <anonymous> = 8; std::true_type = std::integral_constant<bool, true>]' used before its definition In file included from /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/functional:59, from <source>:1: /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/std_function.h: In instantiation of 'std::function<_Res(_ArgTypes ...)>::function(_Functor&&) [with _Functor = double (*)(); _Constraints = void; _Res = double; _ArgTypes = {}]': <source>:8:15: required from here /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/std_function.h:436:72: error: 'static constexpr bool std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_S_nothrow_init() [with _Fn = double (*)(); _Res = double; _Functor = double (*)(); _ArgTypes = {}]' used before its definition 436 | noexcept(_Handler<_Functor>::template _S_nothrow_init<_Functor>()) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~ ASM generation compiler returned: 1 In file included from /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/move.h:57, from /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/stl_function.h:60, from /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/functional:49, from <source>:1: /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/type_traits: In instantiation of 'struct std::is_trivially_copyable<double (*)()>': /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/std_function.h:69:12: required from 'struct std::__is_location_invariant<double (*)()>' /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/std_function.h:125:38: required from 'const bool std::_Function_base::_Base_manager<double (*)()>::__stored_locally' /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/std_function.h:130:8: required from 'class std::_Function_base::_Base_manager<double (*)()>' /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/std_function.h:260:11: required from 'class std::_Function_handler<double(), double (*)()>' /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/std_function.h:436:65: required from 'std::function<_Res(_ArgTypes ...)>::function(_Functor&&) [with _Functor = double (*)(); _Constraints = void; _Res = double; _ArgTypes = {}]' <source>:8:15: required from here /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/type_traits:713:52: error: non-constant condition for static assertion 713 | static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/type_traits:713:52: error: 'constexpr std::true_type std::__is_complete_or_unbounded(std::__type_identity<_Tp>) [with _Tp = double (*)(); long unsigned int <anonymous> = 8; std::true_type = std::integral_constant<bool, true>]' used before its definition In file included from /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/functional:59, from <source>:1: /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/std_function.h: In instantiation of 'std::function<_Res(_ArgTypes ...)>::function(_Functor&&) [with _Functor = double (*)(); _Constraints = void; _Res = double; _ArgTypes = {}]': <source>:8:15: required from here /opt/compiler-explorer/gcc-11.3.0/include/c++/11.3.0/bits/std_function.h:436:72: error: 'static constexpr bool std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_S_nothrow_init() [with _Fn = double (*)(); _Res = double; _Functor = double (*)(); _ArgTypes = {}]' used before its definition 436 | noexcept(_Handler<_Functor>::template _S_nothrow_init<_Functor>()) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~ Execution build compiler returned: 1