From patchwork Thu Sep 5 22:44:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 272994 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "www.sourceware.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 5D9642C00F1 for ; Fri, 6 Sep 2013 08:44:29 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=YOB8PmROCmeOt2E9zUNq1vuTIwIGywwzFy5+troSYPC vxSY9Dc4XPinYrAYM1jy1Ou97aeexyxEM8cTaqE2Arbj1kzEmnixUvP8pz5grmP8 spyw1PqnhdQKlaKe0Vk92abJ7fdJl+j/xNjRzKpUogYLecPl8ZaGdr32ypSmoSVw = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=uJ3TSR/Zw50LsV2Erte5WsKV8nA=; b=QutNzNserCNdlK0iv xmaK8lYhwgf2ZYn1PFgYuZh04fAnAOV1yAYcyzo2hl6v1H2c7ca6MTkBf0z0/MVZ eltmo7HgTOJvhAqZBiRIDT9MUUdaDNfEi2VTMFiyhhf0X/3MJ0Ong2lui0zJdeQe EcR5dq2l4zNW8pMrFVYCdu0oAc= Received: (qmail 23054 invoked by alias); 5 Sep 2013 22:44:23 -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 23042 invoked by uid 89); 5 Sep 2013 22:44:22 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Thu, 05 Sep 2013 22:44:22 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_SOFTFAIL, UNPARSEABLE_RELAY autolearn=ham version=3.3.2 X-HELO: aserp1040.oracle.com Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r85MiIlq025258 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 5 Sep 2013 22:44:19 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r85MiETi008695 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 5 Sep 2013 22:44:16 GMT Received: from abhmt113.oracle.com (abhmt113.oracle.com [141.146.116.65]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r85MiE9k008688; Thu, 5 Sep 2013 22:44:14 GMT Received: from poldo4.casa (/79.52.234.122) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Sep 2013 15:44:14 -0700 Message-ID: <5229093C.6050904@oracle.com> Date: Fri, 06 Sep 2013 00:44:12 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 43452 X-IsSubscribed: yes Hi, this very old minor issue is about the kind of diagnostic we want to produce for something like the existing g++.dg/init/delete1.C: class C; void foo(void *p) { delete [] ((C*)p) ; } that is when the array delete is called for a pointer to incomplete type. Currently we emit an hard error (we used to ICE) but arguably we should only warn and explain the possible undefined behavior at runtime, consistently with what we do for the non-array variant of delete (clang and icc likewise warn). I tested the below on x86_64-linux. Thanks! Paolo. /////////////////////// /cp 2013-09-06 PR c++/43452 * init.c (build_vec_delete_1): When the type is incomplete emit a warning not an error. /testsuite 2013-09-06 PR c++/43452 * g++.dg/init/delete1.C: Adjust. Index: cp/init.c =================================================================== --- cp/init.c (revision 202296) +++ cp/init.c (working copy) @@ -3078,7 +3078,7 @@ build_vec_delete_1 (tree base, tree maxindex, tree { tree virtual_size; tree ptype = build_pointer_type (type = complete_type (type)); - tree size_exp = size_in_bytes (type); + tree size_exp; /* Temporary variables used by the loop. */ tree tbase, tbase_init; @@ -3106,6 +3106,22 @@ build_vec_delete_1 (tree base, tree maxindex, tree if (base == error_mark_node || maxindex == error_mark_node) return error_mark_node; + if (!COMPLETE_TYPE_P (type)) + { + if ((complain & tf_warning) + && warning (0, "possible problem detected in invocation of " + "delete [] operator:")) + { + cxx_incomplete_type_diagnostic (base, type, DK_WARNING); + inform (input_location, "neither the destructor nor the " + "class-specific operator delete [] will be called, " + "even if they are declared when the class is defined"); + } + return build_builtin_delete_call (base); + } + + size_exp = size_in_bytes (type); + if (! MAYBE_CLASS_TYPE_P (type) || TYPE_HAS_TRIVIAL_DESTRUCTOR (type)) goto no_destructor; Index: testsuite/g++.dg/init/delete1.C =================================================================== --- testsuite/g++.dg/init/delete1.C (revision 202284) +++ testsuite/g++.dg/init/delete1.C (working copy) @@ -1,7 +1,7 @@ // PR c++/19811 -class C; // { dg-error "forward" } +class C; // { dg-warning "forward" } void foo(void *p) { - delete [] ((C*)p) ; // { dg-error "" } + delete [] ((C*)p) ; // { dg-warning "problem|incomplete" } }