From patchwork Mon Feb 20 18:18:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 730142 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vRsML3dlPz9s72 for ; Tue, 21 Feb 2017 05:18:37 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="QNubXwTP"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=cn239epM+9v27KiH7J4PmNH4CxgZqXU/2A4MUw/RISFEO6 KZYcgbWdWQ4isRu8WnNHOQvaN6f5i73s9s8z+sycetZhtrehph1xSfj+Z2gVkME9 VCAjhhMYN7buqiq/GHbLq+mQHaGrXXeW+2xVU5NAy1XGhkNtRta7asWZQa4W8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=+b2HTbZabg1RNqEE2KPE1wj0c1c=; b=QNubXwTP4BO8ejqy7V62 k2uEpy8htnW9rHb25If8Im5jDW1PKEcPdW7P9cb+2/buUdQXEQRwE7P2XzSXjXdp xogHGpAHt9UIcpSb1amrrCAhEbdgoXNwOmHB260WksslIFrTYWRT3S+YBnNbpv2w 7GxsKEUJKx0+VjUSR/YgaR0= Received: (qmail 72440 invoked by alias); 20 Feb 2017 18:18:28 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 72401 invoked by uid 89); 20 Feb 2017 18:18:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.2 spammy= X-HELO: mail-ot0-f173.google.com Received: from mail-ot0-f173.google.com (HELO mail-ot0-f173.google.com) (74.125.82.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 20 Feb 2017 18:18:25 +0000 Received: by mail-ot0-f173.google.com with SMTP id k4so53553309otc.0 for ; Mon, 20 Feb 2017 10:18:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=5RYratnuTU0pATVeMZRHfjLjYYjQuK1LfkjWzqb/iGk=; b=pok5nMPyXsS7Ktz9mUp0+C+x/XTBcyIF3k+gW9pH9WGry6q5PwSvOvmF7wx+Y2Locc 5qUfEWyGDAnR8UP+iCGF1dT0ONM3kxrs/YS/R/+dPnfl6BWV/bf72WnqgJt5fJ5GMKVY SlpBNesgANKv8adeo6dOmhbAyI6c1QJtXAWtRJhj3RLocXpRYwl8RFD/fipJUZlQ/+be 5Vvu6z8i9g/HPAYk4NupDeFAVTN4NPO9bV6/BT72l38l0UIKJnMhKMNbxXHxWBz7RH6c GCPS1jonx1ZOl3B8Arm+4Nk46BrH6dvzT7Fn7n+tJo74K3wzVqF40MsVXW23WViPV2ty usTw== X-Gm-Message-State: AMke39n1O/kvO0tQVFSvnCBEr9pU1H+CwIJO+toN5p6Y2vBF/ZpIQMyOfUgyoX0spHft52uoUMhv/tNePKpf5X55 X-Received: by 10.157.52.66 with SMTP id v60mr12001463otb.61.1487614704162; Mon, 20 Feb 2017 10:18:24 -0800 (PST) MIME-Version: 1.0 Received: by 10.182.5.4 with HTTP; Mon, 20 Feb 2017 10:18:03 -0800 (PST) From: Jason Merrill Date: Mon, 20 Feb 2017 10:18:03 -0800 Message-ID: Subject: C++ PATCH for c++/78139, private destructor and new-expression To: gcc-patches List X-IsSubscribed: yes The C++17 copy elision code in build_special_member_call was creating a temporary and then eliding the copy directly, but creating that temporary meant building a cleanup, which requires the destructor to be callable. And we shouldn't require that when building a new-expression. Fixed by using the new tf_no_cleanup flag. Tested x86_64-pc-linux-gnu, applying to trunk. commit f41a463a7fba438a5127dc15e1043f287a16e9ad Author: Jason Merrill Date: Sun Feb 19 20:41:23 2017 -0800 PR c++/78139 - destructor needed by new-expression * call.c (build_special_member_call): Use tf_no_cleanup. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index d6d3a8f..93fae0d 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -8356,9 +8356,15 @@ build_special_member_call (tree instance, tree name, vec **args, /* FIXME P0135 doesn't say how to handle direct initialization from a type with a suitable conversion operator. Let's handle it like copy-initialization, but allowing explict conversions. */ + tsubst_flags_t sub_complain = tf_warning; + if (!is_dummy_object (instance)) + /* If we're using this to initialize a non-temporary object, don't + require the destructor to be accessible. */ + sub_complain |= tf_no_cleanup; if (!reference_related_p (class_type, TREE_TYPE (arg))) arg = perform_implicit_conversion_flags (class_type, arg, - tf_warning, flags); + sub_complain, + flags); if ((TREE_CODE (arg) == TARGET_EXPR || TREE_CODE (arg) == CONSTRUCTOR) && (same_type_ignoring_top_level_qualifiers_p diff --git a/gcc/testsuite/g++.dg/init/new48.C b/gcc/testsuite/g++.dg/init/new48.C new file mode 100644 index 0000000..528a582 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/new48.C @@ -0,0 +1,18 @@ +// PR c++/78139 + +struct A +{ + A(int); +private: + ~A(); +}; + +struct B +{ + B(void*); +}; + +int main() +{ + B(new A(42)); +}