public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "milasudril at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107123] New: Size deduction for vector size in template fails Date: Sun, 02 Oct 2022 10:59:32 +0000 [thread overview] Message-ID: <bug-107123-4@http.gcc.gnu.org/bugzilla/> (raw) 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.
next reply other threads:[~2022-10-02 10:59 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-10-02 10:59 milasudril at gmail dot com [this message] 2022-10-03 18:42 ` [Bug c++/107123] " pinskia at gcc dot gnu.org 2022-10-03 18:42 ` pinskia at gcc dot gnu.org 2022-10-03 19:10 ` milasudril at gmail dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-107123-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).