https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107123
Bug ID: 107123 Summary: Size deduction for vector size in template fails Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: milasudril at gmail dot com Target Milestone: --- Host: x86-64_linux_gnu Target: x86-64_linux_gnu I tried to write a generic inner product implementation, accepting vectorized arguments: ```c++ #include <type_traits> #include <cstddef> template<class T> concept arithmetic = std::is_arithmetic_v<T>; template<arithmetic T, size_t N> using native_vector [[gnu::vector_size(sizeof(T)*N)]] = T; template<class T, size_t N> auto inner_product(native_vector<T, N> a, native_vector<T, N> b) { auto const prod = a * b; T ret{}; for(size_t k = 0; k != N; ++k) { ret += prod[k]; } return ret; } auto test(native_vector<int, 4> a, native_vector<int, 4> b) { return inner_product(a, b); } ``` Apparently, it is not possible to deduce N here: ``` <source>: In function 'auto test(native_vector<int, 4>, native_vector<int, 4>)': <source>:23:25: error: no matching function for call to 'inner_product(native_vector<int, 4>&, native_vector<int, 4>&)' 23 | return inner_product(a, b); | ~~~~~~~~~~~~~^~~~~~ <source>:11:6: note: candidate: 'template<class T, long unsigned int N> auto inner_product(native_vector<T, N>, native_vector<T, N>)' 11 | auto inner_product(native_vector<T, N> a, native_vector<T, N> b) | ^~~~~~~~~~~~~ <source>:11:6: note: template argument deduction/substitution failed: <source>:23:25: note: couldn't deduce template parameter 'N' 23 | return inner_product(a, b); ``` I would appreciate if size deduction worked like for std::array: ```c++ #include <array> template<class T, size_t N> auto inner_product(std::array<T, N> a, std::array<T, N> b) { T ret{}; for(size_t k = 0; k != N; ++k) { ret += a[k]*b[k]; } return ret; } auto test(std::array<int, 4> a, std::array<int, 4> b) { return inner_product(a, b); // N deduced to 4 } ``` The problem is present on gcc 10-trunk.