From patchwork Wed Jul 24 21:24:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1136555 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-505646-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="D5pNwGiQ"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="ITmyDEDZ"; dkim-atps=neutral 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 45v7fK5Z49z9sDB for ; Thu, 25 Jul 2019 07:24:56 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=CJlu0f2PZ5hvVMy8HTw+Ik27lpm5ZmEtSIBLgUymEdCYMw4VeG E86cDr3qVS3i733JM9EexdyaDG4XG3tSbtwFkUrmT1R1MrzN59179DypU8Zgq3Cl ACUZYdME+JuoNbK4g0UFckQNVQAqBnY4xOPlWemAy1NoWbs2mQoddlRMs= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=L/f99bZssVNkvB7RTVK++hp03Rs=; b=D5pNwGiQzJUY5zxhd1ZC zwTQ+bbedM8ZSM0W5tVWR66YNOUMZ7L5yy5OXwoB0pJcL3z7JCsGsjMtpLogJA9R Sldm0WZHy5T18x1G7dJMSkJu4c5ZR5NcLFMoWB73dMxD8XQzn/mfmTszHrTNqY/C l0Iaj52TVNEGTTbad9UKjOY= Received: (qmail 71497 invoked by alias); 24 Jul 2019 21:24:49 -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 71487 invoked by uid 89); 24 Jul 2019 21:24:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=paolo, Paolo, dg-warning, dgwarning X-HELO: userp2120.oracle.com Received: from userp2120.oracle.com (HELO userp2120.oracle.com) (156.151.31.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 24 Jul 2019 21:24:47 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x6OLNXFP036453; Wed, 24 Jul 2019 21:24:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=to : cc : from : subject : message-id : date : mime-version : content-type; s=corp-2018-07-02; bh=6bPcpoyn48CMtAzazvUDCR+9qn0ioonqriRWtctdnXo=; b=ITmyDEDZY4xZNZ1BEh/4NQ7vZ708Gi4eGS7ftF7M556jeJyoEoLW9tGbPLOzLkEMsNPC T7YKJhaCQt639IAAJZ6yc2BV6pvja6czGufi2xwpNmmxO4kohd5y2KlUXR6gAUxLTqKy SEQosY4QDl6nNBa83eoM9huG26Pz0eQ8ZcdBBhsDcY+O5WbUY/JHCoXnMMpldaqypP9U Fm1HieHgcdh7M66FGlGPwqwL68VwGUwIIJlFS5obU2zSSR0HiU7bAt7X2NyKCTqaYuPR QdLDankmWQrKCpQrMAwXfgloYnc6vyCqSFkfwPPU9fupTTcJ1U47pXlQ32+0k4yT2CMA 8A== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2tx61byy6g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jul 2019 21:24:43 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x6OLMotD023534; Wed, 24 Jul 2019 21:24:43 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2tx60ybqxb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jul 2019 21:24:43 +0000 Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x6OLOdGJ020271; Wed, 24 Jul 2019 21:24:39 GMT Received: from [192.168.1.4] (/95.247.231.7) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 24 Jul 2019 14:24:38 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Improve delete_sanity locations Message-ID: <5b89d4fe-88b7-b51b-fc0e-11833bde2c34@oracle.com> Date: Wed, 24 Jul 2019 23:24:36 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 X-IsSubscribed: yes Hi, this takes care of the four locations, two warnings and two errors. I'm also adding the missing complain & tf_warning or tf_error guards, I don't have a SFINAE testcase failing but since the function takes a tsubst_flags_t argument I think it's the right thing to do. Tested x86_64-linux. By the way, shall we add to cp-tree.h, at least temporarily, a: inline location_t cp_expr_loc_or_loc (const_tree t) {   return cp_expr_loc_or_loc (t, input_location); } overload? We could use it in a ton of places. Thanks, Paolo. ////////////////////////// /cp 2019-07-24 Paolo Carlini * decl2.c (delete_sanity): Improve diagnostic locations, use cp_expr_loc_or_loc in four places. /testsuite 2019-07-24 Paolo Carlini * g++.dg/diagnostic/delete1.C: New. Index: cp/decl2.c =================================================================== --- cp/decl2.c (revision 273767) +++ cp/decl2.c (working copy) @@ -487,15 +487,19 @@ delete_sanity (tree exp, tree size, bool doing_vec } /* An array can't have been allocated by new, so complain. */ - if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE) - warning (0, "deleting array %q#E", exp); + if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE + && (complain & tf_warning)) + warning_at (cp_expr_loc_or_loc (exp, input_location), 0, + "deleting array %q#E", exp); t = build_expr_type_conversion (WANT_POINTER, exp, true); if (t == NULL_TREE || t == error_mark_node) { - error ("type %q#T argument given to %, expected pointer", - TREE_TYPE (exp)); + if (complain & tf_error) + error_at (cp_expr_loc_or_loc (exp, input_location), + "type %q#T argument given to %, expected pointer", + TREE_TYPE (exp)); return error_mark_node; } @@ -506,8 +510,10 @@ delete_sanity (tree exp, tree size, bool doing_vec /* You can't delete functions. */ if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE) { - error ("cannot delete a function. Only pointer-to-objects are " - "valid arguments to %"); + if (complain & tf_error) + error_at (cp_expr_loc_or_loc (exp, input_location), + "cannot delete a function. Only pointer-to-objects are " + "valid arguments to %"); return error_mark_node; } @@ -514,7 +520,10 @@ delete_sanity (tree exp, tree size, bool doing_vec /* Deleting ptr to void is undefined behavior [expr.delete/3]. */ if (VOID_TYPE_P (TREE_TYPE (type))) { - warning (OPT_Wdelete_incomplete, "deleting %qT is undefined", type); + if (complain & tf_warning) + warning_at (cp_expr_loc_or_loc (exp, input_location), + OPT_Wdelete_incomplete, + "deleting %qT is undefined", type); doing_vec = 0; } Index: testsuite/g++.dg/diagnostic/delete1.C =================================================================== --- testsuite/g++.dg/diagnostic/delete1.C (nonexistent) +++ testsuite/g++.dg/diagnostic/delete1.C (working copy) @@ -0,0 +1,14 @@ +void f () +{ + int a[1]; + delete (a); // { dg-warning "11:deleting array" } + + bool b; + delete (b); // { dg-error "11:type .bool. argument" } + + void g (); + delete (g); // { dg-error "11:cannot delete a function" } + + void* p; + delete (p); // { dg-warning "11:deleting .void*." } +}