https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118227
Bug ID: 118227 Summary: Hard error on unsupported array size when generating deduction guides for an alias template Product: gcc Version: 14.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: bekenn at gmail dot com Target Milestone: --- Code: https://godbolt.org/z/jxE9PW13e #include <span> template <typename T> using dynamic_span = std::span<T>; void example() { int x[5]; dynamic_span d = x; static_assert(std::is_same_v<decltype(d), std::span<int, std::dynamic_extent>>); } error: size '18446744073709551615' of array exceeds maximum object size '9223372036854775807' The initialization of d prompts the generation of deduction guides for the alias template dynamic_span; these guides are based on existing deduction guides for std::span, which include the following: namespace std { template<class T, size_t N> span(T (&)[N]) -> span<T, N>; } This deduction guide is transformed into the equivalent of: template<class T> dynamic_span(T (&)[std::dynamic_extent]) -> std::span<T, std::dynamic_extent>; ...and this is where GCC runs into a problem. std::dynamic_extent is size_t(-1), which is apparently invalid as an array bound, and GCC emits an error diagnostic to that effect. This is contrary to the rules in the standard, which essentially states that a substitution failure at this point simply removes the guide from consideration; [over.match.class.deduct/3]: "If substitution succeeds, form a function or function template f’ with the following properties and add it to the set of guides of A: [...]" This substitution should not result in a hard error or even a warning; instead, the guide should be silently removed from consideration.