From patchwork Sat Aug 4 12:46:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 175106 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]) by ozlabs.org (Postfix) with SMTP id 1A20B2C008E for ; Sat, 4 Aug 2012 22:46:54 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1344689215; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Message-ID:Date:From:User-Agent:MIME-Version: To:CC:Subject:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=5gHatDN4TFkhbqcgCI2Fs3F0FW8=; b=RxBOFPnSZCSXWA3 hYR0jy+OCaSvbtKUrvogz5lHlW5Hhj6khzVRicvgZoYzS/Rsrz2tx+V44swR7Mq/ HV7zedKXvwF+tdNJpfLp4WpTvAN2DKko9tpCRJFhex6w/FhAORW48FrHngbZBNga GVa9nDaLNfRiCjNCZ05qQOs2Sa54= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=De6FvEcLq2wYOXghRKHFukH7AheGiqD4MQk/GYbllmflegdHUSObIZxnRfQX/s UsZgY0RGRCCSzk0VAY9V+FGNEX5BwqWHByMtcVe+fcOdYj12Uit7cmjYm4+k22nD +acXNkGnqtuTztrXTjpMzIq9ETnbJIwIJ+HzVsz30eRt8=; Received: (qmail 12635 invoked by alias); 4 Aug 2012 12:46:51 -0000 Received: (qmail 12626 invoked by uid 22791); 4 Aug 2012 12:46:51 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from rcsinet15.oracle.com (HELO rcsinet15.oracle.com) (148.87.113.117) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 04 Aug 2012 12:46:37 +0000 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by rcsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q74CkaI3019778 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 4 Aug 2012 12:46:37 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q74CkZgt008754 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 4 Aug 2012 12:46:36 GMT Received: from abhmt101.oracle.com (abhmt101.oracle.com [141.146.116.53]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q74CkZZo016213; Sat, 4 Aug 2012 07:46:35 -0500 Received: from [192.168.1.4] (/79.33.217.9) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 04 Aug 2012 05:46:35 -0700 Message-ID: <501D19A7.4030403@oracle.com> Date: Sat, 04 Aug 2012 14:46:31 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 54161 X-IsSubscribed: yes 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 Hi, as discussed on the audit trail, I'm changing c_sizeof_or_alignof_type to unconditionally pedwarn in C++ mode. I have to also tweak an existing testcase, which was exactly relying on the warning to be suppressed by -Wno-pointer-arith. Booted and tested x86_64-linux. Thanks, Paolo. ///////////////// /c-family 2012-08-04 Paolo Carlini PR c++/54161 * c-common.c (c_sizeof_or_alignof_type): In C++, pedwarn for function type and void type without -pedantic and -Wpointer-arith too. /testsuite 2012-08-04 Paolo Carlini PR c++/54161 * g++.dg/warn/pr54161.C: New. * g++.old-deja/g++.jason/ambig2.C: Adjust. Index: c-family/c-common.c =================================================================== --- c-family/c-common.c (revision 190141) +++ c-family/c-common.c (working copy) @@ -4578,10 +4578,17 @@ 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, - "invalid application of % to a function type"); - else if (!complain) + if (complain) + { + if (c_dialect_cxx ()) + pedwarn (loc, 0, "invalid application of % to " + "a function type"); + else if (pedantic || warn_pointer_arith) + pedwarn (loc, pedantic ? OPT_Wpedantic : OPT_Wpointer_arith, + "invalid application of % to " + "a function type"); + } + else return error_mark_node; value = size_one_node; } @@ -4601,12 +4608,17 @@ 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, - "invalid application of %qs to a void type", op_name); + if (complain && type_code == VOID_TYPE) + { + if (c_dialect_cxx ()) + pedwarn (loc, 0, + "invalid application of %qs to a void type", op_name); + else if (pedantic || warn_pointer_arith) + pedwarn (loc, pedantic ? OPT_Wpedantic : OPT_Wpointer_arith, + "invalid application of %qs to a void type", op_name); + } else if (!complain) - return error_mark_node; + return error_mark_node; value = size_one_node; } else if (!COMPLETE_TYPE_P (type) Index: testsuite/g++.old-deja/g++.jason/ambig2.C =================================================================== --- testsuite/g++.old-deja/g++.jason/ambig2.C (revision 190141) +++ testsuite/g++.old-deja/g++.jason/ambig2.C (working copy) @@ -2,10 +2,8 @@ // { dg-options "-Wno-pointer-arith" } // Testcase for ambiguity between cast and parmlist. // This ambiguity accounts for 1 of the r/r conflicts. -// Do not compile with -pedantic so that the compiler will accept taking -// the sizeof a function type. void f(){ (void)sizeof(int((int)1.2)); - (void)sizeof(int((int))); // { dg-bogus "" } + (void)sizeof(int((int))); // { dg-warning "invalid application" } } Index: testsuite/g++.dg/warn/pr54161.C =================================================================== --- testsuite/g++.dg/warn/pr54161.C (revision 0) +++ testsuite/g++.dg/warn/pr54161.C (revision 0) @@ -0,0 +1,12 @@ +// PR c++/54161 +// { dg-options "-Wno-pointer-arith" } + +void f(); +void (&g())(); + +const int a = sizeof(void); // { dg-warning "invalid application" } +const int b = sizeof(void()); // { dg-warning "invalid application" } +const int c = sizeof(f()); // { dg-warning "invalid application" } +const int d = sizeof(g()); // { dg-warning "invalid application" } + +typedef char test[a + b + c + d > 0 ? 1 : -1];