From patchwork Thu Jul 30 09:24:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 502032 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 DC10E140788 for ; Thu, 30 Jul 2015 19:24:40 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=EMRCCrpQ; 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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=eDFTyOk6Aa4djuNsazyizKCfZnxS+xae5a8Ct189lFXdOBIGov kbPhPeXWc1Y4neZXw/5R/+2eGpyYRfyHsX4OMN+s95sMwLVNcVnyPoYfwptZq8oR emshmLTtUpuT5VW3zrg7WMJpx3cdb0JqKXOq4dSHtqBBIoApIgXHtWBFk= 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 :from:subject:message-id:date:mime-version:content-type; s= default; bh=qvQQCumM+KEE+NECk/JwgBU2HmY=; b=EMRCCrpQvtDG29nxZQ5+ TC0ljpniyewrEsYpJJlXdBwPl/qfGf+rNVv2wWzUbh+WU4/cJSNIhVhZbJsF7lOg maHuHH5Rjf+EcSRf+lKVp3TNkIQ41kw3Q9Of0wGuaBVss7iIVGIyqn4CzJDwxgvG ByayDWxZxjtGkb2bWPR+l4o= Received: (qmail 10919 invoked by alias); 30 Jul 2015 09:24: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 10893 invoked by uid 89); 30 Jul 2015 09:24:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.4 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 30 Jul 2015 09:24:23 +0000 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t6U9OKph025203 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 30 Jul 2015 09:24:21 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id t6U9OKpC027438 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Thu, 30 Jul 2015 09:24:20 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id t6U9OJEC010960 for ; Thu, 30 Jul 2015 09:24:20 GMT Received: from [192.168.1.4] (/79.37.220.215) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Jul 2015 02:24:19 -0700 To: "gcc-patches@gcc.gnu.org" From: Paolo Carlini Subject: [C++ Patch, preapproved] Prefer DECL_SOURCE_LOCATION to "+D" and "+#D" (3/n) Message-ID: <55B9ED41.2020701@oracle.com> Date: Thu, 30 Jul 2015 11:24:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, for the time being this is the last installment. As anticipated, in some cases (4 overall) I'm using location_of instead of the simple DECL_SOURCE_LOCATION: in the case of note_name_declared_in_class the testsuite would pass anyway, but I prefer to be safe. Tested x86_64-linux. Thanks, Paolo. /////////////////////////// 2015-07-30 Paolo Carlini * class.c (check_for_override): Use DECL_SOURCE_LOCATION and "%qD" in warning_at instead of "%q+D" in warning. (warn_hidden): Likewise but use location_of. (finish_struct_anon_r): Likewise use DECL_SOURCE_LOCATION in permerror. (check_bitfield_decl, check_field_decls): Likewise in warning_at. (check_field_decls): Likewise for permerror. (explain_non_literal_class): Likewise for inform. (check_bases_and_members, layout_class_type): Likewise for warning_at. (note_name_declared_in_class): Use location_of in permerror. * name-lookup.c (diagnose_name_conflict): Use location_of in inform. (pushdecl_maybe_friend_1): Use DECL_SOURCE_LOCATION in pedwarn, inform, and warning_at. (check_for_out_of_scope_variable): Likewise for warning_at and permerror. Index: class.c =================================================================== --- class.c (revision 226388) +++ class.c (working copy) @@ -2926,7 +2926,7 @@ check_for_override (tree decl, tree ctype) if (warn_override && !DECL_OVERRIDE_P (decl) && !DECL_DESTRUCTOR_P (decl)) warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wsuggest_override, - "%q+D can be marked override", decl); + "%qD can be marked override", decl); } if (DECL_VIRTUAL_P (decl)) @@ -3007,9 +3007,12 @@ warn_hidden (tree t) FOR_EACH_VEC_ELT (base_fndecls, k, base_fndecl) if (base_fndecl) { - /* Here we know it is a hider, and no overrider exists. */ - warning (OPT_Woverloaded_virtual, "%q+D was hidden", base_fndecl); - warning (OPT_Woverloaded_virtual, " by %q+D", fns); + /* Here we know it is a hider, and no overrider exists. */ + warning_at (location_of (base_fndecl), + OPT_Woverloaded_virtual, + "%qD was hidden", base_fndecl); + warning_at (location_of (fns), + OPT_Woverloaded_virtual, " by %qD", fns); } } } @@ -3042,12 +3045,12 @@ finish_struct_anon_r (tree field, bool complain) if (complain && !VAR_P (elt)) { if (is_union) - permerror (input_location, - "%q+#D invalid; an anonymous union can " + permerror (DECL_SOURCE_LOCATION (elt), + "%q#D invalid; an anonymous union can " "only have non-static data members", elt); else - permerror (input_location, - "%q+#D invalid; an anonymous struct can " + permerror (DECL_SOURCE_LOCATION (elt), + "%q#D invalid; an anonymous struct can " "only have non-static data members", elt); } continue; @@ -3058,20 +3061,20 @@ finish_struct_anon_r (tree field, bool complain) if (TREE_PRIVATE (elt)) { if (is_union) - permerror (input_location, - "private member %q+#D in anonymous union", elt); + permerror (DECL_SOURCE_LOCATION (elt), + "private member %q#D in anonymous union", elt); else - permerror (input_location, - "private member %q+#D in anonymous struct", elt); + permerror (DECL_SOURCE_LOCATION (elt), + "private member %q#D in anonymous struct", elt); } else if (TREE_PROTECTED (elt)) { if (is_union) - permerror (input_location, - "protected member %q+#D in anonymous union", elt); + permerror (DECL_SOURCE_LOCATION (elt), + "protected member %q#D in anonymous union", elt); else - permerror (input_location, - "protected member %q+#D in anonymous struct", elt); + permerror (DECL_SOURCE_LOCATION (elt), + "protected member %q#D in anonymous struct", elt); } } @@ -3460,11 +3463,14 @@ check_bitfield_decl (tree field) || ((TREE_CODE (type) == ENUMERAL_TYPE || TREE_CODE (type) == BOOLEAN_TYPE) && tree_int_cst_lt (TYPE_SIZE (type), w))) - warning (0, "width of %q+D exceeds its type", field); + warning_at (DECL_SOURCE_LOCATION (field), 0, + "width of %qD exceeds its type", field); else if (TREE_CODE (type) == ENUMERAL_TYPE && (0 > (compare_tree_int (w, TYPE_PRECISION (ENUM_UNDERLYING_TYPE (type)))))) - warning (0, "%q+D is too small to hold all values of %q#T", field, type); + warning_at (DECL_SOURCE_LOCATION (field), 0, + "%qD is too small to hold all values of %q#T", + field, type); } if (w != error_mark_node) @@ -3737,9 +3743,9 @@ check_field_decls (tree t, tree *access_decls, { if (!layout_pod_type_p (type) && !TYPE_PACKED (type)) { - warning - (0, - "ignoring packed attribute because of unpacked non-POD field %q+#D", + warning_at + (DECL_SOURCE_LOCATION (x), 0, + "ignoring packed attribute because of unpacked non-POD field %q#D", x); cant_pack = 1; } @@ -3854,7 +3860,8 @@ check_field_decls (tree t, tree *access_decls, user-declared constructor. */ if (constructor_name_p (DECL_NAME (x), t) && TYPE_HAS_USER_CONSTRUCTOR (t)) - permerror (input_location, "field %q+#D with same name as class", x); + permerror (DECL_SOURCE_LOCATION (x), + "field %q#D with same name as class", x); } /* Effective C++ rule 11: if a class has dynamic memory held by pointers, @@ -5623,14 +5630,15 @@ explain_non_literal_class (tree t) ftype = TREE_TYPE (field); if (!literal_type_p (ftype)) { - inform (0, " non-static data member %q+D has " - "non-literal type", field); + inform (DECL_SOURCE_LOCATION (field), + " non-static data member %qD has non-literal type", + field); if (CLASS_TYPE_P (ftype)) explain_non_literal_class (ftype); } if (CP_TYPE_VOLATILE_P (ftype)) - inform (0, " non-static data member %q+D has " - "volatile type", field); + inform (DECL_SOURCE_LOCATION (field), + " non-static data member %qD has volatile type", field); } } } @@ -5775,13 +5783,15 @@ check_bases_and_members (tree t) type = TREE_TYPE (field); if (TREE_CODE (type) == REFERENCE_TYPE) - warning (OPT_Wuninitialized, "non-static reference %q+#D " - "in class without a constructor", field); + warning_at (DECL_SOURCE_LOCATION (field), + OPT_Wuninitialized, "non-static reference %q#D " + "in class without a constructor", field); else if (CP_TYPE_CONST_P (type) && (!CLASS_TYPE_P (type) || !TYPE_HAS_DEFAULT_CONSTRUCTOR (type))) - warning (OPT_Wuninitialized, "non-static const member %q+#D " - "in class without a constructor", field); + warning_at (DECL_SOURCE_LOCATION (field), + OPT_Wuninitialized, "non-static const member %q#D " + "in class without a constructor", field); } } @@ -6322,8 +6332,9 @@ layout_class_type (tree t, tree *virtuals_p) && !integer_zerop (size_binop (TRUNC_MOD_EXPR, DECL_FIELD_BIT_OFFSET (field), bitsize_unit_node))) - warning (OPT_Wabi, "offset of %q+D is not ABI-compliant and may " - "change in a future version of GCC", field); + warning_at (DECL_SOURCE_LOCATION (field), OPT_Wabi, + "offset of %qD is not ABI-compliant and may " + "change in a future version of GCC", field); /* The middle end uses the type of expressions to determine the possible range of expression values. In order to optimize @@ -8113,8 +8124,9 @@ note_name_declared_in_class (tree name, tree decl) in its context and when re-evaluated in the completed scope of S. */ permerror (input_location, "declaration of %q#D", decl); - permerror (input_location, "changes meaning of %qD from %q+#D", - DECL_NAME (OVL_CURRENT (decl)), (tree) n->value); + permerror (location_of ((tree) n->value), + "changes meaning of %qD from %q#D", + DECL_NAME (OVL_CURRENT (decl)), (tree) n->value); } } Index: name-lookup.c =================================================================== --- name-lookup.c (revision 226388) +++ name-lookup.c (working copy) @@ -590,7 +590,7 @@ diagnose_name_conflict (tree decl, tree bval) else error ("%q#D conflicts with a previous declaration", decl); - inform (input_location, "previous declaration %q+#D", bval); + inform (location_of (bval), "previous declaration %q#D", bval); } /* Wrapper for supplement_binding_1. */ @@ -875,8 +875,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend) pedwarn (input_location, 0, "declaration of %q#D with C language linkage", x); - pedwarn (input_location, 0, - "conflicts with previous declaration %q+#D", + pedwarn (DECL_SOURCE_LOCATION (previous), 0, + "conflicts with previous declaration %q#D", previous); pedwarn (input_location, 0, "due to different exception specifications"); @@ -890,8 +890,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend) { pedwarn (input_location, 0, "declaration of %q#D with C language linkage", x); - pedwarn (input_location, 0, - "conflicts with previous declaration %q+#D", + pedwarn (DECL_SOURCE_LOCATION (previous), 0, + "conflicts with previous declaration %q#D", previous); } } @@ -992,8 +992,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend) { if (permerror (input_location, "type mismatch with previous " "external decl of %q#D", x)) - inform (input_location, "previous external decl of %q+#D", - decl); + inform (DECL_SOURCE_LOCATION (decl), + "previous external decl of %q#D", decl); } } @@ -1082,7 +1082,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend) else { warning (0, "extern declaration of %q#D doesn%'t match", x); - warning (0, "global declaration %q+#D", oldglobal); + warning_at (DECL_SOURCE_LOCATION (oldglobal), 0, + "global declaration %q#D", oldglobal); } } /* If we have a local external declaration, @@ -1170,8 +1171,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend) || oldscope->kind == sk_for)) { error ("redeclaration of %q#D", x); - inform (input_location, "%q+#D previously declared here", - oldlocal); + inform (DECL_SOURCE_LOCATION (oldlocal), + "%q#D previously declared here", oldlocal); nowarn = true; } /* C++11: @@ -1193,8 +1194,8 @@ pushdecl_maybe_friend_1 (tree x, bool is_friend) && in_function_try_handler)) { if (permerror (input_location, "redeclaration of %q#D", x)) - inform (input_location, "%q+#D previously declared here", - oldlocal); + inform (DECL_SOURCE_LOCATION (oldlocal), + "%q#D previously declared here", oldlocal); nowarn = true; } @@ -1410,9 +1411,11 @@ check_for_out_of_scope_variable (tree decl) if (!DECL_ERROR_REPORTED (decl)) { warning (0, "name lookup of %qD changed", DECL_NAME (decl)); - warning (0, " matches this %q+D under ISO standard rules", - shadowed); - warning (0, " matches this %q+D under old rules", decl); + warning_at (DECL_SOURCE_LOCATION (shadowed), 0, + " matches this %qD under ISO standard rules", + shadowed); + warning_at (DECL_SOURCE_LOCATION (decl), 0, + " matches this %qD under old rules", decl); DECL_ERROR_REPORTED (decl) = 1; } return shadowed; @@ -1441,7 +1444,8 @@ check_for_out_of_scope_variable (tree decl) permerror (input_location, "name lookup of %qD changed for ISO % scoping", DECL_NAME (decl)); if (flag_permissive) - permerror (input_location, " using obsolete binding at %q+D", decl); + permerror (DECL_SOURCE_LOCATION (decl), + " using obsolete binding at %qD", decl); else { static bool hint;