From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BA65D3858D28; Thu, 28 Dec 2023 04:11:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA65D3858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1703736690; bh=kHsUCGW2QgbN01rpafyXghDYzldT8kLV8G351GiKR6w=; h=From:To:Subject:Date:From; b=hdsqoJN9hv5TsnQeXA/mlteIEewD2cs8JI1Anw90XXx++i30lXVwHRdaVu7SMr2eW x1JnHXnr2aX0EbYFdjM1omOAbwJkbxIt7VM31+lecySX9ZIUVF+n36BKdKyf7mZy8R vgz2CFs7lvGCMPa9gvvQK4SyinF0R5jaBRWSfyCY= From: "yihuajack at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/113160] New: Const valarray (g)slice and indirect_array fail to match valarray in template functions Date: Thu, 28 Dec 2023 04:11:29 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: yihuajack 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 attachments.created 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=3D113160 Bug ID: 113160 Summary: Const valarray (g)slice and indirect_array fail to match valarray in template functions Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: yihuajack at gmail dot com Target Milestone: --- Created attachment 56957 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D56957&action=3Dedit Output GCC version: 13.2.0, etc. System type: MinGW-w64 3.4.10.x86_64, etc. Options: -std=3Dc++23, etc. Command line: g++ -std=3Dc++23 -save-temps test2.cpp Outputs are attached. Reproducer: #include #include template void foo(const std::valarray &va) { std::cout << va[0] << '\n'; } int main() { const std::valarray vmask =3D {1, 0, 0, 1}; const std::valarray vind =3D {1, 3}; const std::valarray va =3D {1, 2, 3, 4}; foo(va[std::slice(1, 2, 1)]); foo(va[std::gslice(0, {1, 1}, {1, 1})]); foo(va[vmask]); foo(va[vind]); } The code can be successfully compiled by MSVC v19.38.33130 and v19.latest f= or x86/x64 but failed to be compiled by GCC 13.2.0 or trunk. If function foo() is not a template function, i.e., void foo(const std::valarray &va) { std::cout << va[0] << '\n'; } Then the code compiles. If the valarray is not const, then it returns a std::valarray, std::gslice_array, std::mask_array, or std::indirect_array, which makes no dissent - the compiler refuses to match std::valarray with it. However, thi= s is not the case for a const valarray. According to the Working Draft, Standard= for Programming Language C++ (N4950): Any function returning a valarray is permitted to return an object of anoth= er type, provided all the const member functions of valarray are also applicable to this type. This return type shall not add more than two levels of template nesting over the most deeply nested argume= nt type. 4 Implementations introducing such replacement types shall provide addition= al functions and operators as follows: (4.1) =E2=80=94 for every function taking a const valarray& other than begi= n and end (28.6.10), identical functions taking the replacement types shall be added; (4.2) =E2=80=94 for every function taking two const valarray& arguments, id= entical functions taking every combi- nation of const valarray& and replacement types shall be added. For libstdc++, the replacement types (mask_array is an exception - the oper= ator function directly returns a valarray, so it compiles) are _Expr<_SClos<_ValArray, _Tp>, _Tp> _Expr<_GClos<_ValArray, _Tp>, _Tp> _Expr<_IClos<_ValArray, _Tp>, _Tp> which refuse to match const std::valarray &, which might be a violation = of the C++ standard.=