From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id B786E3858D39; Thu, 23 Sep 2021 10:21:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B786E3858D39 Received: by mail-wr1-x42f.google.com with SMTP id g16so15730393wrb.3; Thu, 23 Sep 2021 03:21:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=TW7yOMbCwZ12wqJKBfiwKlNO1XGCIHa7vt+KIHVoJnI=; b=XIY8oYAVLInQQpNVQsezrCEWPyjuh93tyCOHfjkg2ugE1YCPe2LpZvq1J41ej0s09I 9WgsPFUS7p1UW4RKv9in6pGVTQKwoPfXnq5FSX0aT1T9NQGdIjuOFwiiq6/Tzu/il3XB u0qQbTozXq0OrrSqdP0sKOTWWIXUWbaG9AvW6ze0swVJpamXoyY1+WwsD/v4rJhMsouA 9+sJP9SD7UZSfEsBC75HaPp8sP802Cb55X27Ze7Vh16XF+cMUc4SNEWj1mpcg0TqLZ4u 4/+0vacBSinCaA2aMTU+h4ZU9/C3f10TBdk8oE/u5e7E5L2IURLAqaGbAVlBC/ui/X7x ceJg== X-Gm-Message-State: AOAM533uC5lkEag/P5CxlYNTugCoRDIWy4kraFWShcrm48XOGNCgW2Ei B6h1RxLsVVRi8DqqxjF8CdRnTVBQxSoaxV6GvE4= X-Google-Smtp-Source: ABdhPJwx0OUs3tqOxS61v0p04ilRYaVbRHZjWFeKeifDnbcbeymtUe2BvHR4om3KlgKxz2XtEHeNflByHw+PvZxRqxo= X-Received: by 2002:a5d:4481:: with SMTP id j1mr4224630wrq.6.1632392506794; Thu, 23 Sep 2021 03:21:46 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Thu, 23 Sep 2021 11:21:35 +0100 Message-ID: Subject: Re: [PATCH] assert that deleting by pointer to base in unique_ptr does not cause UB To: Antony Polukhin Cc: "libstdc++" , gcc-patches List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Sep 2021 10:21:49 -0000 On Wed, 22 Sept 2021 at 18:56, Antony Polukhin wrote: > > =D1=81=D1=80, 22 =D1=81=D0=B5=D0=BD=D1=82. 2021 =D0=B3. =D0=B2 20:44, Jon= athan Wakely : > > > > On Wed, 22 Sept 2021 at 18:09, Antony Polukhin wrote: > > > > > > std::unique_ptr allows construction from std::unique_ptr of derived > > > type as per [unique.ptr.single.asgn] and [unique.ptr.single.ctor]. If > > > std::default_delete is used with std::unique_ptr, then after such > > > construction a delete is called on a pointer to base. According to > > > [expr.delete] calling a delete on a non similar object without a > > > virtual destructor is an undefined behavior. > > > > > > This patch turns that undefined behavior into static assertions insid= e > > > std::unique_ptr. > > > > The undefined behaviour only happens if the destructor is actually > > reached at runtime, but won't these static assertions make it > > ill-formed to instantiate these members, even if the UB never happens? > > > > For example, if you ensure that release() is called before > > destruction, the undefined delete never happens. > > Ugh... I've missed that use case. Patch is just wrong, discard it It's a horrible (and probably unrealistic) use case, but we're required to accept it. I should a test case to the testsuite, just to make sure we continue to accept it without errors.