From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 13D7F3858C2C; Wed, 22 Sep 2021 17:23:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 13D7F3858C2C Received: by mail-wr1-x42b.google.com with SMTP id t18so9199403wrb.0; Wed, 22 Sep 2021 10:23:11 -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; bh=8GsO3KtL7aexSmAge7UtF1tyJPTCwyb+IhzU97FncjQ=; b=pRtPd1EjdjNB0VayG36on3uiZoL6LvcForfztlS1ifRfDk0AjYJV62uguR7NuG56G3 hh0aIG2RAboo6fzlzhSDIRGS6H5UKqg6/ME+T/c8DthnJ3qR4gYF7RblIqsyIw+JZM9d pVMjO4/l6Qtp990Koihwezxm+XGry/44Y30/IJYOltF6wL71uU3884eq1GXg2+msy6YX Y6ZH2Z+c95YdJq7kM2svKid0PHZvb0z1aEgJW2eST/WiIgZ+tkSKwZNSDlfc59BfU2gG dBGn9JnQuIO6C0SuCGdVmYdDcpBicGHuWwihd81vRgV5lzjjHeiXQvZA/Zx6/JC1GQ0H cr1w== X-Gm-Message-State: AOAM53308qtcJqgCY1nGaLBtqYYhv+We/YIW24VnVmIAz3hdsDeAVBuP pn2hi4SoklzezwXffx0n6r/w3uUukloq9eR9lAM= X-Google-Smtp-Source: ABdhPJwrjgN6vCGKU+PYch3bbAzWiCYMQEFZBQhd5Q/6TuVmgd8LxM2ULIXkDTnIrBN9XTt3bRLyRuI4G+V5tJXeTkM= X-Received: by 2002:a5d:460a:: with SMTP id t10mr89384wrq.145.1632331390016; Wed, 22 Sep 2021 10:23:10 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ville Voutilainen Date: Wed, 22 Sep 2021 20:22:58 +0300 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" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, 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: Wed, 22 Sep 2021 17:23:12 -0000 On Wed, 22 Sept 2021 at 20:09, Antony Polukhin via Libstdc++ 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 inside > std::unique_ptr. I don't understand the sizeof(_Tp) == sizeof(_Up) part in the static_assert. I fail to see how a same-size check suggests that the types are similar enough that a delete-expression works.