From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C2477385743B; Sat, 17 Jul 2021 11:56:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2477385743B From: "dennis-hezel at gmx dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/101485] New: Calling std::equal with std::byte* does not use memcmp Date: Sat, 17 Jul 2021 11:56:20 +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.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dennis-hezel at gmx dot de 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 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Jul 2021 11:56:20 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101485 Bug ID: 101485 Summary: Calling std::equal with std::byte* does not use memcmp Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dennis-hezel at gmx dot de Target Milestone: --- See https://godbolt.org/z/fKbhqe1sz ``` #include auto equal_with_bytes(std::byte* b1, std::byte* e1, std::byte* b2) { return std::equal(b1, e1, b2); } auto equal_with_chars(unsigned char* b1, unsigned char* e1, unsigned char* = b2) { return std::equal(b1, e1, b2); } ``` In the above code `equal_with_chars` invokes `memcmp` while `equal_with_byt= es` does not, although it would be eligble. The problematic code seems to be in `stl_algobase.h` ``` template _GLIBCXX20_CONSTEXPR inline bool __equal_aux1(_II1 __first1, _II1 __last1, _II2 __first2) { typedef typename iterator_traits<_II1>::value_type _ValueType1; const bool __simple =3D ((__is_integer<_ValueType1>::__value || __is_pointer<_ValueType1>::__value) && __memcmpable<_II1, _II2>::__value); return std::__equal<__simple>::equal(__first1, __last1, __first2); }=20 ``` since `std::byte` is neither an integer nor a pointer. Suggested fix: Extend the condition with a check for `std::byte` ``` __is_integer<_ValueType1>::__value || __is_pointer<_ValueType1>::__value || __is_byte<_ValueType1>::__value ```=