From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 81EFA3858C2C; Sun, 2 Oct 2022 10:59:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 81EFA3858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664708373; bh=hMZPx9QgqmtddkGxQhRwH+dGiJg9wCvevfGp24bbvAs=; h=From:To:Subject:Date:From; b=XzifSRZPoRLDUwHIzzh+twdyAs8+q9Jr2ZS42wATfyjJDTe//C16ehGi+Ltv98cS2 mSPIa83afgg8qUFxxZqH6ofmXTykBNcxLs+s7yc5Bie0NvoFFreE58/ZUDyXTW7EEE f11v/1InR++59dCKhuZNMPLw3baMFGXXeCdyWWx4= From: "milasudril at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: milasudril at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone cf_gcchost cf_gcctarget Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107123 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 vectoriz= ed arguments: ```c++ #include #include template concept arithmetic =3D std::is_arithmetic_v; template using native_vector [[gnu::vector_size(sizeof(T)*N)]] =3D T; template auto inner_product(native_vector a, native_vector b) { auto const prod =3D a * b; T ret{}; for(size_t k =3D 0; k !=3D N; ++k) { ret +=3D prod[k]; } return ret; } auto test(native_vector a, native_vector b) { return inner_product(a, b); } ``` Apparently, it is not possible to deduce N here: ``` : In function 'auto test(native_vector, native_vector)': :23:25: error: no matching function for call to 'inner_product(native_vector&, native_vector&)' 23 | return inner_product(a, b); | ~~~~~~~~~~~~~^~~~~~ :11:6: note: candidate: 'template auto inner_product(native_vector, native_vector)' 11 | auto inner_product(native_vector a, native_vector b) | ^~~~~~~~~~~~~ :11:6: note: template argument deduction/substitution failed: :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 template auto inner_product(std::array a, std::array b) { T ret{}; for(size_t k =3D 0; k !=3D N; ++k) { ret +=3D a[k]*b[k]; } return ret; } auto test(std::array a, std::array b) { return inner_product(a, b); // N deduced to 4 } ``` The problem is present on gcc 10-trunk.=