From patchwork Fri Jun 15 14:16:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 929964 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-479801-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="E/roqfqf"; 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 416jGz6bJrz9s2R for ; Sat, 16 Jun 2018 00:16:59 +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=uQBrf1BekMkpSVSg+ELzTFB3BEHCX+gwh05Q4YHFyRO1lqxdwE wrwgPINcSOpRE0e2pFJEzYmi25hfhhA9iKYeKgX0+EVq3h76Bp1myzorhFQqeNwH TL2ewtx+4c4PcxU74jJjXTtnRsdI/7czQvnZ9NLcUnJZaLvUOyXzZQrAc= 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=Ot6Ft75O6qhYupxfod0JdMPUxg4=; b=E/roqfqfaM3cvnAeAaQs uBSgO+W5u1GPIYzgjlxgYLdBgPQOxiHyJIqGkJYSSPOdRp/d7Va/36ww9kWaBtiw fdYnrkKXX23Y3ejLCayR9jJlbG6w5g/jgKnlpedSzKep6l24pmtur5jaqvxqzjgP XXvoBGnlSPok2L/dP3gSP70= Received: (qmail 56313 invoked by alias); 15 Jun 2018 14:16:42 -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 56233 invoked by uid 89); 15 Jun 2018 14:16:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=ignoring, nonfunction, non-function 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; Fri, 15 Jun 2018 14:16:36 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w5FEESEI086053; Fri, 15 Jun 2018 14:16:35 GMT Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2jk0xrh82v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jun 2018 14:16:34 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w5FEGX9H002960 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jun 2018 14:16:34 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w5FEGX0p007310; Fri, 15 Jun 2018 14:16:33 GMT Received: from [192.168.1.4] (/87.11.64.97) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 15 Jun 2018 07:16:29 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Tidy duplicate_decls locations Message-ID: <90b3d025-299d-d415-8f56-ef11ae44d5c4@oracle.com> Date: Fri, 15 Jun 2018 16:16:26 +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=8924 signatures=668702 X-IsSubscribed: yes Hi, these bits started when I realized that in the error messages about redefined default arguments we were using DECL_SOURCE_LOCATION for the olddecl and just input_location for newdecl: in the future we'll able to point at the specific default argument but for the time being we can as well be consistent and point at the function name for the newdecl too instead of the meaningless closing parenthesis. Then I realized that in the rather large duplicate_decls we were using a mix of DECL_SOURCE_LOCATION (olddecl) and newdecl - lots - and '+' in a rather inconsistent way. Tested x86_64-linux. Thanks, Paolo. ///////////////////// 2018-06-15 Paolo Carlini * decl.c (duplicate_decls): Consistently use DECL_SOURCE_LOCATION in errors about redefined default arguments; tidy. Index: decl.c =================================================================== --- decl.c (revision 261621) +++ decl.c (working copy) @@ -1319,6 +1319,8 @@ duplicate_decls (tree newdecl, tree olddecl, bool int olddecl_friend = 0, types_match = 0, hidden_friend = 0; int new_defines_function = 0; tree new_template_info; + location_t olddecl_loc = DECL_SOURCE_LOCATION (olddecl); + location_t newdecl_loc = DECL_SOURCE_LOCATION (newdecl); if (newdecl == olddecl) return olddecl; @@ -1342,13 +1344,15 @@ duplicate_decls (tree newdecl, tree olddecl, bool if (TREE_CODE (newdecl) == TEMPLATE_DECL && TREE_CODE (olddecl) != TEMPLATE_DECL && check_raw_literal_operator (olddecl)) - error ("literal operator template %q+D conflicts with" - " raw literal operator %qD", newdecl, olddecl); + error_at (newdecl_loc, + "literal operator template %qD conflicts with" + " raw literal operator %qD", newdecl, olddecl); else if (TREE_CODE (newdecl) != TEMPLATE_DECL && TREE_CODE (olddecl) == TEMPLATE_DECL && check_raw_literal_operator (newdecl)) - error ("raw literal operator %q+D conflicts with" - " literal operator template %qD", newdecl, olddecl); + error_at (newdecl_loc, + "raw literal operator %qD conflicts with" + " literal operator template %qD", newdecl, olddecl); } /* True to merge attributes between the declarations, false to @@ -1366,10 +1370,10 @@ duplicate_decls (tree newdecl, tree olddecl, bool && diagnose_mismatched_attributes (olddecl, newdecl)) { if (DECL_INITIAL (olddecl)) - inform (DECL_SOURCE_LOCATION (olddecl), + inform (olddecl_loc, "previous definition of %qD was here", olddecl); else - inform (DECL_SOURCE_LOCATION (olddecl), + inform (olddecl_loc, "previous declaration of %qD was here", olddecl); } @@ -1386,7 +1390,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool { if (TREE_PUBLIC (newdecl) && CP_DECL_CONTEXT (newdecl) == global_namespace) - warning_at (DECL_SOURCE_LOCATION (newdecl), + warning_at (newdecl_loc, OPT_Wbuiltin_declaration_mismatch, "built-in function %qD declared as non-function", newdecl); @@ -1398,7 +1402,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool bad choice of name. */ if (! TREE_PUBLIC (newdecl)) { - warning_at (DECL_SOURCE_LOCATION (newdecl), + warning_at (newdecl_loc, OPT_Wshadow, DECL_BUILT_IN (olddecl) ? G_("shadowing built-in function %q#D") @@ -1409,20 +1413,21 @@ duplicate_decls (tree newdecl, tree olddecl, bool /* If the built-in is not ansi, then programs can override it even globally without an error. */ else if (! DECL_BUILT_IN (olddecl)) - warning_at (DECL_SOURCE_LOCATION (newdecl), 0, + warning_at (newdecl_loc, 0, "library function %q#D redeclared as non-function %q#D", olddecl, newdecl); else - error ("declaration of %q+#D conflicts with built-in " - "declaration %q#D", newdecl, olddecl); + error_at (newdecl_loc, + "declaration of %q#D conflicts with built-in " + "declaration %q#D", newdecl, olddecl); return NULL_TREE; } else if (DECL_OMP_DECLARE_REDUCTION_P (olddecl)) { gcc_assert (DECL_OMP_DECLARE_REDUCTION_P (newdecl)); - error_at (DECL_SOURCE_LOCATION (newdecl), + error_at (newdecl_loc, "redeclaration of %"); - inform (DECL_SOURCE_LOCATION (olddecl), + inform (olddecl_loc, "previous % declaration"); return error_mark_node; } @@ -1481,7 +1486,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool next_arg:; } - warning_at (DECL_SOURCE_LOCATION (newdecl), + warning_at (newdecl_loc, OPT_Wbuiltin_declaration_mismatch, "declaration of %q#D conflicts with built-in " "declaration %q#D", newdecl, olddecl); @@ -1510,16 +1515,16 @@ next_arg:; { if (DECL_INITIAL (newdecl)) { - error_at (DECL_SOURCE_LOCATION (newdecl), + error_at (newdecl_loc, "definition of %q#D ambiguates built-in " "declaration %q#D", newdecl, olddecl); return error_mark_node; } - if (permerror (DECL_SOURCE_LOCATION (newdecl), + if (permerror (newdecl_loc, "new declaration %q#D ambiguates built-in" " declaration %q#D", newdecl, olddecl) && flag_permissive) - inform (DECL_SOURCE_LOCATION (newdecl), + inform (newdecl_loc, "ignoring the %q#D declaration", newdecl); return flag_permissive ? olddecl : error_mark_node; } @@ -1528,7 +1533,7 @@ next_arg:; /* A near match; override the builtin. */ if (TREE_PUBLIC (newdecl)) - warning_at (DECL_SOURCE_LOCATION (newdecl), + warning_at (newdecl_loc, OPT_Wbuiltin_declaration_mismatch, "new declaration %q#D ambiguates built-in " "declaration %q#D", newdecl, olddecl); @@ -1624,7 +1629,7 @@ next_arg:; error ("%q#D redeclared as different kind of symbol", newdecl); if (TREE_CODE (olddecl) == TREE_LIST) olddecl = TREE_VALUE (olddecl); - inform (DECL_SOURCE_LOCATION (olddecl), + inform (olddecl_loc, "previous declaration %q#D", olddecl); return error_mark_node; @@ -1644,8 +1649,9 @@ next_arg:; if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL) { - error ("conflicting declaration of template %q+#D", newdecl); - inform (DECL_SOURCE_LOCATION (olddecl), + error_at (newdecl_loc, + "conflicting declaration of template %q#D", newdecl); + inform (olddecl_loc, "previous declaration %q#D", olddecl); return error_mark_node; } @@ -1663,8 +1669,9 @@ next_arg:; // constraints. && equivalently_constrained (olddecl, newdecl)) { - error ("ambiguating new declaration %q+#D", newdecl); - inform (DECL_SOURCE_LOCATION (olddecl), + error_at (newdecl_loc, "ambiguating new declaration %q#D", + newdecl); + inform (olddecl_loc, "old declaration %q#D", olddecl); } else if (check_concept_refinement (olddecl, newdecl)) @@ -1675,9 +1682,10 @@ next_arg:; { if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl)) { - error ("conflicting declaration of C function %q+#D", - newdecl); - inform (DECL_SOURCE_LOCATION (olddecl), + error_at (newdecl_loc, + "conflicting declaration of C function %q#D", + newdecl); + inform (olddecl_loc, "previous declaration %q#D", olddecl); return NULL_TREE; } @@ -1691,8 +1699,9 @@ next_arg:; // And the same constraints. && equivalently_constrained (newdecl, olddecl)) { - error ("ambiguating new declaration of %q+#D", newdecl); - inform (DECL_SOURCE_LOCATION (olddecl), + error_at (newdecl_loc, + "ambiguating new declaration of %q#D", newdecl); + inform (olddecl_loc, "old declaration %q#D", olddecl); return error_mark_node; } @@ -1701,8 +1710,8 @@ next_arg:; } else { - error ("conflicting declaration %q+#D", newdecl); - inform (DECL_SOURCE_LOCATION (olddecl), + error_at (newdecl_loc, "conflicting declaration %q#D", newdecl); + inform (olddecl_loc, "previous declaration as %q#D", olddecl); return error_mark_node; } @@ -1757,9 +1766,9 @@ next_arg:; const char *errmsg = redeclaration_error_message (newdecl, olddecl); if (errmsg) { - error_at (DECL_SOURCE_LOCATION (newdecl), errmsg, newdecl); + error_at (newdecl_loc, errmsg, newdecl); if (DECL_NAME (olddecl) != NULL_TREE) - inform (DECL_SOURCE_LOCATION (olddecl), + inform (olddecl_loc, (DECL_INITIAL (olddecl) && namespace_bindings_p ()) ? G_("%q#D previously defined here") : G_("%q#D previously declared here"), olddecl); @@ -1771,9 +1780,9 @@ next_arg:; && prototype_p (TREE_TYPE (newdecl))) { /* Prototype decl follows defn w/o prototype. */ - if (warning_at (DECL_SOURCE_LOCATION (newdecl), 0, + if (warning_at (newdecl_loc, 0, "prototype specified for %q#D", newdecl)) - inform (DECL_SOURCE_LOCATION (olddecl), + inform (olddecl_loc, "previous non-prototype definition here"); } else if (VAR_OR_FUNCTION_DECL_P (olddecl) @@ -1812,9 +1821,10 @@ next_arg:; } else { - error ("conflicting declaration of %q+#D with %qL linkage", - newdecl, DECL_LANGUAGE (newdecl)); - inform (DECL_SOURCE_LOCATION (olddecl), + error_at (newdecl_loc, + "conflicting declaration of %q#D with %qL linkage", + newdecl, DECL_LANGUAGE (newdecl)); + inform (olddecl_loc, "previous declaration with %qL linkage", DECL_LANGUAGE (olddecl)); } @@ -1848,18 +1858,19 @@ next_arg:; if (simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)) == 1) { - if (permerror (input_location, + if (permerror (newdecl_loc, "default argument given for parameter " "%d of %q#D", i, newdecl)) - inform (DECL_SOURCE_LOCATION (olddecl), + inform (olddecl_loc, "previous specification in %q#D here", olddecl); } else { - error ("default argument given for parameter %d " - "of %q#D", i, newdecl); - inform (DECL_SOURCE_LOCATION (olddecl), + error_at (newdecl_loc, + "default argument given for parameter %d " + "of %q#D", i, newdecl); + inform (olddecl_loc, "previous specification in %q#D here", olddecl); } @@ -1924,11 +1935,11 @@ next_arg:; && (! DECL_TEMPLATE_SPECIALIZATION (newdecl) || DECL_TEMPLATE_SPECIALIZATION (olddecl))) { - if (warning_at (DECL_SOURCE_LOCATION (newdecl), + if (warning_at (newdecl_loc, OPT_Wredundant_decls, "redundant redeclaration of %qD in same scope", newdecl)) - inform (DECL_SOURCE_LOCATION (olddecl), + inform (olddecl_loc, "previous declaration of %qD", olddecl); } @@ -1937,8 +1948,8 @@ next_arg:; { if (DECL_DELETED_FN (newdecl)) { - error ("deleted definition of %q+D", newdecl); - inform (DECL_SOURCE_LOCATION (olddecl), + error_at (newdecl_loc, "deleted definition of %qD", newdecl); + inform (olddecl_loc, "previous declaration of %qD", olddecl); } DECL_DELETED_FN (newdecl) |= DECL_DELETED_FN (olddecl); @@ -2507,10 +2518,10 @@ next_arg:; && DECL_VISIBILITY_SPECIFIED (newdecl) && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl)) { - if (warning_at (DECL_SOURCE_LOCATION (newdecl), OPT_Wattributes, + if (warning_at (newdecl_loc, OPT_Wattributes, "%qD: visibility attribute ignored because it " "conflicts with previous declaration", newdecl)) - inform (DECL_SOURCE_LOCATION (olddecl), + inform (olddecl_loc, "previous declaration of %qD", olddecl); } /* Choose the declaration which specified visibility. */