From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 673AD3858C2B; Sat, 5 Nov 2022 01:04:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 673AD3858C2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667610263; bh=zDBoPa4qlxYdrDu+yz9z0Ailw5P6SMWi0ukrjzkvW/I=; h=From:To:Subject:Date:From; b=kuFCzdebvCihs21FXoN6zVopn7akMzRPq/A8PqGZMiN+NtkECCjj31YD/wMAtmPqy AUOBGCH1wJRZDPhmOZMz02unxa97qnpdigTthbQ70dE9IUh59ihpw7vDim5YfgAtcS 9Y9YoSJqMqVkSutoc8KU3F9kKacdz3k+qD06UJYg= From: "vanyacpp at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107529] New: constexpr evaluator doesn't check for destroyed objects Date: Sat, 05 Nov 2022 01:04:23 +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: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vanyacpp 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 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=3D107529 Bug ID: 107529 Summary: constexpr evaluator doesn't check for destroyed objects Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: vanyacpp at gmail dot com Target Milestone: --- I believe this function contains undefined behavior and should not be allow= ed to evaluate at compile-time. The call to `std::destroy_at(p)` should end the lifetime of `*p` and access= es to `*p` after that should be invalid. #include struct mytype { constexpr mytype() : x(42) {} constexpr ~mytype() {} int x; }; constexpr int foo() { std::allocator alloc; mytype* p =3D alloc.allocate(1); std::construct_at(p); std::destroy_at(p); // destroy *p int result =3D p->x; // access alloc.deallocate(p, 1); return result; } static_assert(foo() =3D=3D 42);=