From patchwork Tue Jun 12 08:07:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 928181 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-479517-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="Es/JZDr5"; 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 414jD72BCrz9s0W for ; Tue, 12 Jun 2018 18:07:34 +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=nSeBikEUtvYLJEajbD6fmrT4krmi+Z57keHKIxvnuiBChgIpr7 zJl67qt13SCRlfjVIw2VOyMcVpUW227fms70R73j4qiOKsKxLk2csvhpqdqnlr7n zKcDuQWhJEzxAgWQlSuaF5SSYoH4rbLUasAT4LLcDmHlserYcIAWiLTY4= 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=j7lOXKrj1dtWP6BGuchUNEUqXYQ=; b=Es/JZDr5AqGhpQhL4nX7 t144dK771DhZh8KsX2RzN7Rylni+Ut4VMJ7ktkZo2DxWliH5ljcMoSzEObD3kFeY A8O4rtJ4OoDJPpmHNIigOnseUZjrjUIT2thZ9homtz7qrGh1TAt4IN7xOOZbT5Q1 IU5O9Ai8YaeS/VUpMge2IIs= Received: (qmail 12694 invoked by alias); 12 Jun 2018 08:07:26 -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 12591 invoked by uid 89); 12 Jun 2018 08:07:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=yesterday X-HELO: aserp2130.oracle.com Received: from aserp2130.oracle.com (HELO aserp2130.oracle.com) (141.146.126.79) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Jun 2018 08:07:12 +0000 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w5C86TKu170064; Tue, 12 Jun 2018 08:07:10 GMT Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2jg4dm10bq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Jun 2018 08:07:10 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w5C879m8013807 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Jun 2018 08:07:10 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w5C879sg003253; Tue, 12 Jun 2018 08:07:09 GMT Received: from [192.168.1.4] (/87.11.64.97) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 12 Jun 2018 01:07:08 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Fix coerce_new_type and coerce_delete_type locations Message-ID: <1c783f15-16dc-accd-0e59-a6fdeb78e5ef@oracle.com> Date: Tue, 12 Jun 2018 10:07:05 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8921 signatures=668702 X-IsSubscribed: yes Hi, yesterday I didn't notice that grok_op_properties calls a couple of helpers which are affected by exactly the same location issues. The below simply forwards the location to the helpers. Tested x86_64-linux. Thanks, Paolo. //////////////////////// /cp 2018-06-12 Paolo Carlini * decl2.c (coerce_new_type, coerce_delete_type): Add location_t parameter and adjust error_at calls. * decl.c (grok_op_properties): Adjust calls. * cp-tree.h (oerce_new_type, coerce_delete_type): Adjust decls. /testsuite 2018-06-12 Paolo Carlini * g++.dg/init/delete3.C: New. * g++.dg/init/new49.C: Likewise. * g++.dg/init/new25.C: Test locations too. * g++.dg/template/new4.C: Likewise. * g++.old-deja/g++.jason/operator.C: Likewise. Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 261457) +++ cp/cp-tree.h (working copy) @@ -6346,8 +6346,8 @@ extern bool attributes_naming_typedef_ok (tree); extern void cplus_decl_attributes (tree *, tree, int); extern void finish_anon_union (tree); extern void cxx_post_compilation_parsing_cleanups (void); -extern tree coerce_new_type (tree); -extern tree coerce_delete_type (tree); +extern tree coerce_new_type (tree, location_t); +extern tree coerce_delete_type (tree, location_t); extern void comdat_linkage (tree); extern void determine_visibility (tree); extern void constrain_class_visibility (tree); Index: cp/decl.c =================================================================== --- cp/decl.c (revision 261457) +++ cp/decl.c (working copy) @@ -13153,11 +13153,11 @@ grok_op_properties (tree decl, bool complain) } if (op_flags & OVL_OP_FLAG_DELETE) - TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl)); + TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl), loc); else { DECL_IS_OPERATOR_NEW (decl) = 1; - TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl)); + TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl), loc); } return true; Index: cp/decl2.c =================================================================== --- cp/decl2.c (revision 261457) +++ cp/decl2.c (working copy) @@ -1676,7 +1676,7 @@ finish_anon_union (tree anon_union_decl) what compiler will be expecting. */ tree -coerce_new_type (tree type) +coerce_new_type (tree type, location_t loc) { int e = 0; tree args = TYPE_ARG_TYPES (type); @@ -1686,7 +1686,8 @@ tree if (!same_type_p (TREE_TYPE (type), ptr_type_node)) { e = 1; - error ("% must return type %qT", ptr_type_node); + error_at (loc, "% must return type %qT", + ptr_type_node); } if (args && args != void_list_node) @@ -1697,8 +1698,8 @@ tree The first parameter shall not have an associated default argument. */ - error ("the first parameter of % cannot " - "have a default argument"); + error_at (loc, "the first parameter of % cannot " + "have a default argument"); /* Throw away the default argument. */ TREE_PURPOSE (args) = NULL_TREE; } @@ -1713,7 +1714,7 @@ tree e = 2; if (e == 2) - permerror (input_location, "% takes type % (%qT) " + permerror (loc, "% takes type % (%qT) " "as first parameter", size_type_node); switch (e) @@ -1732,7 +1733,7 @@ tree } tree -coerce_delete_type (tree type) +coerce_delete_type (tree type, location_t loc) { int e = 0; tree args = TYPE_ARG_TYPES (type); @@ -1742,7 +1743,8 @@ tree if (!same_type_p (TREE_TYPE (type), void_type_node)) { e = 1; - error ("% must return type %qT", void_type_node); + error_at (loc, "% must return type %qT", + void_type_node); } if (!args || args == void_list_node @@ -1751,8 +1753,8 @@ tree e = 2; if (args && args != void_list_node) args = TREE_CHAIN (args); - error ("% takes type %qT as first parameter", - ptr_type_node); + error_at (loc, "% takes type %qT as first parameter", + ptr_type_node); } switch (e) { Index: testsuite/g++.dg/init/delete3.C =================================================================== --- testsuite/g++.dg/init/delete3.C (nonexistent) +++ testsuite/g++.dg/init/delete3.C (working copy) @@ -0,0 +1 @@ +int operator delete (void*, int); // { dg-error "5:.operator delete. must return type .void." } Index: testsuite/g++.dg/init/new25.C =================================================================== --- testsuite/g++.dg/init/new25.C (revision 261457) +++ testsuite/g++.dg/init/new25.C (working copy) @@ -4,14 +4,14 @@ class C { public: - void* operator new(std::size_t = 32) throw (std::bad_alloc); // { dg-error "first parameter" } + void* operator new(std::size_t = 32) throw (std::bad_alloc); // { dg-error "9:the first parameter of .operator new. cannot have a default argument" } // { dg-error "dynamic exception specification" "" { target c++17 } .-1 } // { dg-warning "deprecated" "" { target { c++11 && { ! c++17 } } } .-2 } - void* operator new[](std::size_t = 32) throw (std::bad_alloc); // { dg-error "first parameter" } + void* operator new[](std::size_t = 32) throw (std::bad_alloc); // { dg-error "9:the first parameter of .operator new. cannot have a default argument" } // { dg-error "dynamic exception specification" "" { target c++17 } .-1 } // { dg-warning "deprecated" "" { target { c++11 && { ! c++17 } } } .-2 } - void* operator new(std::size_t = 32, const std::nothrow_t&) throw(); // { dg-error "first parameter" } - void* operator new[](std::size_t = 32, const std::nothrow_t&) throw(); // { dg-error "first parameter" } + void* operator new(std::size_t = 32, const std::nothrow_t&) throw(); // { dg-error "9:the first parameter of .operator new. cannot have a default argument" } + void* operator new[](std::size_t = 32, const std::nothrow_t&) throw(); // { dg-error "9:the first parameter of .operator new. cannot have a default argument" } }; class D @@ -26,8 +26,8 @@ class D class E { public: - void* operator new(std::size_t = 0, - const std::nothrow_t& = std::nothrow_t()) throw(); // { dg-error "first parameter" } - void* operator new[](std::size_t = 0, - const std::nothrow_t& = std::nothrow_t()) throw(); // { dg-error "first parameter" } + void* operator new(std::size_t = 0, // { dg-error "9:the first parameter of .operator new. cannot have a default argument" } + const std::nothrow_t& = std::nothrow_t()) throw(); + void* operator new[](std::size_t = 0, // { dg-error "9:the first parameter of .operator new. cannot have a default argument" } + const std::nothrow_t& = std::nothrow_t()) throw(); }; Index: testsuite/g++.dg/init/new49.C =================================================================== --- testsuite/g++.dg/init/new49.C (nonexistent) +++ testsuite/g++.dg/init/new49.C (working copy) @@ -0,0 +1 @@ +int operator new (__SIZE_TYPE__, int); // { dg-error "5:.operator new. must return type .void*." } Index: testsuite/g++.dg/template/new4.C =================================================================== --- testsuite/g++.dg/template/new4.C (revision 261457) +++ testsuite/g++.dg/template/new4.C (working copy) @@ -4,5 +4,6 @@ struct A { template - static void* operator new(T) {} // { dg-error "first parameter|invalid template" } + static void* operator new(T) {} // { dg-error "invalid template" } +// { dg-error "18:.operator new. takes type .size_t." "first" { target *-*-* } .-1 } }; Index: testsuite/g++.old-deja/g++.jason/operator.C =================================================================== --- testsuite/g++.old-deja/g++.jason/operator.C (revision 261457) +++ testsuite/g++.old-deja/g++.jason/operator.C (working copy) @@ -25,8 +25,8 @@ struct B { int operator-(int a, int b); // { dg-error "5:.int operator-\\(int, int\\). must have an argument of class or enumerated type" } -void * operator new (A a); // { dg-error "first parameter" } -void operator delete (A a); // { dg-error "first parameter" } +void * operator new (A a); // { dg-error ".operator new. takes type .size_t." } +void operator delete (A a); // { dg-error ".operator delete. takes type .void\\*. as first parameter" } char * operator char * (int); // { dg-error "return type" "ret" } // { dg-error "8:.operator char\\*\\*\\(int\\). must be a nonstatic member function" "mem" { target *-*-* } .-1 }