From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 934E83858401; Wed, 4 Oct 2023 17:46:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 934E83858401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696441619; bh=99kSED7U3EIc+DjxlCDUkQ87SrRHVwmWi/CADItWTWQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FmMcpxpmFe2r9dAaicdv3WFSibRhnzUODcnHfcUGcK8dGuEm8wxMYf7GlYtLPM0Dw CrggWiJv3NXJZfXZF3yCUk9L5ALtgT9xBTJg86KauGbvfM8+b8YVM4RvDphN/JeRL1 H9h50MNUF3oR07WGfWhFaUWxItQiqvfuYWFQyl7g= From: "fchelnokov at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/111685] Segfault while sorting on array element address Date: Wed, 04 Oct 2023 17:46:59 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: fchelnokov 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: Message-ID: In-Reply-To: References: 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=3D111685 --- Comment #10 from Fedor Chelnokov --- It seems that both libc++ and MS STL implement std::sort without a temporary object passed to cmp, because they are fine with compiling the following co= de in constant expression (where unrelated pointers cannot be compared): consteval void foo() { std::array nums{1, 5, 4}; auto cmp =3D [](auto& a, auto& b) { return &a < &b; }; std::sort(nums.begin(), nums.end(), cmp); } Online demo: https://godbolt.org/z/jdecfP6c4 Is it right that their implementations are less optimal because of no tempo= rary object?=