From patchwork Thu Apr 4 23:07:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 233981 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 "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id D80F02C00A2 for ; Fri, 5 Apr 2013 10:08:19 +1100 (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=nkAnZ7oMVNLzwNsLD/1P/Gkcuzw4YtY4nUO1G8N1NPX qKG2MOT1psZV5TbYUR+e+V5jLscNvroUgXDxHlcxoweRuRJUU6iZeZOmFwfN5pMh o8wftC8aXdi3sNgVz9uqYL8IFifVEeNK4IzP/E2Z77CBUUv53X1sAnf0Yb08vW2g = 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=FitvdKcjjpEjjcOsM1CglGAIRcM=; b=qTgYIfxPbddoomIAr K9B3hVOFV8UrFsmhD7M0eL7Oj1jgeq9uXyx1t+wBCNrvnWcnL8aujuLAtQpHZZMI 41GEL7FpS5k7bSpVJkFv+2y/Hh5g3+Cl1XiXrEcWDFO0AO95g9vDtXdhJ575NU6q +SS7WCZwaBTJggNakTeuWzypJs= Received: (qmail 26568 invoked by alias); 4 Apr 2013 23:08:09 -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 26556 invoked by uid 89); 4 Apr 2013 23:08:09 -0000 X-Spam-SWARE-Status: No, score=-5.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, TW_PF autolearn=ham version=3.3.1 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 04 Apr 2013 23:08:06 +0000 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r34N7wdx014095 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 4 Apr 2013 23:07:58 GMT Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r34N7uVn013729 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 4 Apr 2013 23:07:57 GMT Received: from abhmt114.oracle.com (abhmt114.oracle.com [141.146.116.66]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r34N7u87009157; Thu, 4 Apr 2013 18:07:56 -0500 Received: from [192.168.1.4] (/79.25.197.113) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 04 Apr 2013 16:07:56 -0700 Message-ID: <515E07C9.40608@oracle.com> Date: Fri, 05 Apr 2013 01:07:53 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill , "Joseph S. Myers" Subject: [C++/C Patch] Have -Wpointer-arith enable by -Wpedantic, as documented X-Virus-Found: No Hi, in the audit trail of c++/56815 Manuel noticed that, inconsistently with the documentation, a LangEnabledBy was missing for -Wpointer-arith vs -Wpedantic. Then I noticed that a clean up was possible in the actual pedwarn calls, which, in fact, also fixes a bug: we don't want to actually emit such warnings for -Wpedantic -Wno-pointer-arith (as would happen before and after the trivial tweak above) I booted & tested the below on x86_64-linux. Thanks, Paolo. /////////////////////////// /c-family 2013-04-04 Paolo Carlini Manuel Lopez-Ibanez * c.opt ([Wpointer-arith]): Enabled by -Wpedantic, as documented. * c-common.c (pointer_int_sum): Change -Wpointer-arith pedwarns to simply use OPT_Wpointer_arith. (c_sizeof_or_alignof_type): Likewise. /cp 2013-04-04 Paolo Carlini * typeck.c (cxx_sizeof_or_alignof_type): Change -Wpointer-arith pedwarn to simply use OPT_Wpointer_arith. (cp_build_unary_op): Likewise. /c 2013-04-04 Paolo Carlini * c-typeck.c (pointer_diff): Change -Wpointer-arith pedwarns to simply use OPT_Wpointer_arith. (build_unary_op): Likewise. /testsuite 2013-04-04 Paolo Carlini * c-c++-common/Wpointer-arith-1.c: New. Index: c/c-typeck.c =================================================================== --- c/c-typeck.c (revision 197495) +++ c/c-typeck.c (working copy) @@ -3333,10 +3333,10 @@ pointer_diff (location_t loc, tree op0, tree op1) if (TREE_CODE (target_type) == VOID_TYPE) - pedwarn (loc, pedantic ? OPT_Wpedantic : OPT_Wpointer_arith, + pedwarn (loc, OPT_Wpointer_arith, "pointer of type % used in subtraction"); if (TREE_CODE (target_type) == FUNCTION_TYPE) - pedwarn (loc, pedantic ? OPT_Wpedantic : OPT_Wpointer_arith, + pedwarn (loc, OPT_Wpointer_arith, "pointer to a function used in subtraction"); /* If the conversion to ptrdiff_type does anything like widening or @@ -3663,10 +3663,10 @@ build_unary_op (location_t location, || TREE_CODE (TREE_TYPE (argtype)) == VOID_TYPE) { if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) - pedwarn (location, pedantic ? OPT_Wpedantic : OPT_Wpointer_arith, + pedwarn (location, OPT_Wpointer_arith, "wrong type argument to increment"); else - pedwarn (location, pedantic ? OPT_Wpedantic : OPT_Wpointer_arith, + pedwarn (location, OPT_Wpointer_arith, "wrong type argument to decrement"); } Index: c-family/c-common.c =================================================================== --- c-family/c-common.c (revision 197495) +++ c-family/c-common.c (working copy) @@ -4280,13 +4280,13 @@ pointer_int_sum (location_t loc, enum tree_code re if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE) { - pedwarn (loc, pedantic ? OPT_Wpedantic : OPT_Wpointer_arith, + pedwarn (loc, OPT_Wpointer_arith, "pointer of type % used in arithmetic"); size_exp = integer_one_node; } else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE) { - pedwarn (loc, pedantic ? OPT_Wpedantic : OPT_Wpointer_arith, + pedwarn (loc, OPT_Wpointer_arith, "pointer to a function used in arithmetic"); size_exp = integer_one_node; } @@ -4864,8 +4864,8 @@ c_sizeof_or_alignof_type (location_t loc, { if (is_sizeof) { - if (complain && (pedantic || warn_pointer_arith)) - pedwarn (loc, pedantic ? OPT_Wpedantic : OPT_Wpointer_arith, + if (complain && warn_pointer_arith) + pedwarn (loc, OPT_Wpointer_arith, "invalid application of % to a function type"); else if (!complain) return error_mark_node; @@ -4888,8 +4888,8 @@ c_sizeof_or_alignof_type (location_t loc, else if (type_code == VOID_TYPE || type_code == ERROR_MARK) { if (type_code == VOID_TYPE - && complain && (pedantic || warn_pointer_arith)) - pedwarn (loc, pedantic ? OPT_Wpedantic : OPT_Wpointer_arith, + && complain && warn_pointer_arith) + pedwarn (loc, OPT_Wpointer_arith, "invalid application of %qs to a void type", op_name); else if (!complain) return error_mark_node; Index: c-family/c.opt =================================================================== --- c-family/c.opt (revision 197495) +++ c-family/c.opt (working copy) @@ -614,7 +614,7 @@ C++ ObjC++ Var(warn_pmf2ptr) Init(1) Warning Warn when converting the type of pointers to member functions Wpointer-arith -C ObjC C++ ObjC++ Var(warn_pointer_arith) Warning +C ObjC C++ ObjC++ Var(warn_pointer_arith) Warning LangEnabledBy(C ObjC C++ ObjC++,Wpedantic) Warn about function pointer arithmetic Wpointer-sign Index: cp/typeck.c =================================================================== --- cp/typeck.c (revision 197495) +++ cp/typeck.c (working copy) @@ -1522,7 +1522,7 @@ cxx_sizeof_or_alignof_type (tree type, enum tree_c if (TREE_CODE (type) == METHOD_TYPE) { if (complain) - pedwarn (input_location, pedantic ? OPT_Wpedantic : OPT_Wpointer_arith, + pedwarn (input_location, OPT_Wpointer_arith, "invalid application of %qs to a member function", operator_name_info[(int) op].name); value = size_one_node; @@ -5577,8 +5577,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, else if (!TYPE_PTROB_P (argtype)) { if (complain & tf_error) - pedwarn (input_location, - pedantic ? OPT_Wpedantic : OPT_Wpointer_arith, + pedwarn (input_location, OPT_Wpointer_arith, (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) ? G_("ISO C++ forbids incrementing a pointer of type %qT") Index: testsuite/c-c++-common/Wpointer-arith-1.c =================================================================== --- testsuite/c-c++-common/Wpointer-arith-1.c (revision 0) +++ testsuite/c-c++-common/Wpointer-arith-1.c (working copy) @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-Wpedantic -Wno-pointer-arith" } */ + +void h(void) +{ + typedef void (*pft) (); + typedef void (ft) (); + + void *pv = 0; + pft pf = 0; + + pv++; + pf++; + + --pv; + --pf; + + pv += 1; + pf += 1; + + pv = pv - 1; + pf = pf - 1; + + sizeof (void); + sizeof (ft); +}