From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 787813858414; Mon, 7 Aug 2023 09:13:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 787813858414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691399583; bh=d/P2lgi7bf2N9ZemJM7BZr2ns8DC/Dsa06UKFZMrPNA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qAQAtWfnwUd82NMnKzp+VCnB6QvFaxcp8ZQDFn+JzcmTpJs9v30BK9VTpcv1pnt9B 0ApoRSc7SmEyDVYTS9T2IW/WUsmY0CnZn6wmh+A6/VsRAXH1JgrS9bcKZzG6a+Qmq1 +qJxazKY5Ab8IjcZ6ChwN7DOA6u+W0nQFxkgeEM8= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110619] Dangling pointer returned from constexpr function converts in nullptr Date: Mon, 07 Aug 2023 09:12:57 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: accepts-invalid, diagnostic, rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org 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=3D110619 --- Comment #9 from Jonathan Wakely --- (In reply to Fedor Chelnokov from comment #8) > This program must be rejected because of relational comparison of unrelat= ed > pointers I disagree. If GCC were to define the behaviour of returning invalid pointe= rs during constant evaluation as converting them to null pointers, then those wouldn't be unrelated pointers. They'd be null pointers. And the comparison would be well defined. But I don't think that conversion was ever intended as the defined behaviou= r, just an unintended consequence. If it was intended, it should have been documented at https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Implementation.html The fact that we _don't_ do any such conversion should also be documented there, of course. We should say that other uses of invalid pointers do not modify the pointer values, so copying them preserves the invalid value (wit= hout trapping, except on Itanium?) and pointer comparisons and pointer arithmetic are undefined because they don't point to an object.=