From patchwork Thu Dec 18 16:31:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 422600 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 3AD561400F1 for ; Fri, 19 Dec 2014 03:32:05 +1100 (AEDT) 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:subject:references :in-reply-to:content-type; q=dns; s=default; b=jLlf9SiT1Aw4Vi32u dfnDPHwX2btwIeKXKA0a8vMhAGQZR3DtkGr4DOHzAnw9vTcFaqLZT9kJL3JK6pjF fsiq1tFDKlBQTvAQEBbYIE2G3nBwPRNRt+bWJIP7qHxMCYptfg2fpCC18owuZ2Sp vNUf5Y8qtCC12nP0O7CNsD/Ul4= 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:subject:references :in-reply-to:content-type; s=default; bh=orgwLX7/m9ycDN0zrc3HcMg fG1o=; b=rnuMnuZEfIaWxRnbXhBIvTjxu2YgWtux4bDebbHle/B20Pz/oLWlI5i 4NBr61gRY4Yvw9Z9ovbem1zTa5VdWlTO12R9CKR51kAfnEtsLayk97YgkKfnvgJk Bqpte2v6ee+9cOGMQYuLeo9IaURs5tSJbrUkZFnTSAzss+MYWJfk= Received: (qmail 29253 invoked by alias); 18 Dec 2014 16:31:57 -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 29239 invoked by uid 89); 18 Dec 2014 16:31:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL, BAYES_00, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: aserp1040.oracle.com Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Thu, 18 Dec 2014 16:31:55 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id sBIGVqPu005810 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 18 Dec 2014 16:31:53 GMT Received: from userz7022.oracle.com (userz7022.oracle.com [156.151.31.86]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id sBIGVoUw014767 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 18 Dec 2014 16:31:52 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userz7022.oracle.com (8.14.5+Sun/8.14.4) with ESMTP id sBIGVnL9003844; Thu, 18 Dec 2014 16:31:50 GMT Received: from [192.168.1.4] (/79.37.237.29) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 18 Dec 2014 08:31:49 -0800 Message-ID: <54930173.4030104@oracle.com> Date: Thu, 18 Dec 2014 17:31:47 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Jason Merrill , "gcc-patches@gcc.gnu.org" Subject: Re: [C++ Patch] PR 60955 References: <54889DF2.7060704@oracle.com> <5491E982.3090506@redhat.com> <5492B7B7.8060402@oracle.com> <5492E2BD.1040602@redhat.com> In-Reply-To: <5492E2BD.1040602@redhat.com> X-IsSubscribed: yes Hi, On 12/18/2014 03:20 PM, Jason Merrill wrote: > On 12/18/2014 06:17 AM, Paolo Carlini wrote: >> Sure. The below uses the c_inhibit_evaluation_warnings mechanism and >> passes testing. I wondered if in such cases we could alternately use the >> warning_sentinel mechanism (moved to cp-tree.h of course) ? > That would make sense to me. Good. Then I'm finishing testing the below. Thanks, Paolo. //////////////////// Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 218857) +++ cp/cp-tree.h (working copy) @@ -1149,6 +1149,18 @@ struct processing_template_decl_sentinel } }; +/* RAII sentinel to disable certain warnings during template substitution + and elsewhere. */ + +struct warning_sentinel +{ + int &flag; + int val; + warning_sentinel(int& flag, bool suppress=true) + : flag(flag), val(flag) { if (suppress) flag = 0; } + ~warning_sentinel() { flag = val; } +}; + /* The cached class binding level, from the most recently exited class, or NULL if none. */ Index: cp/pt.c =================================================================== --- cp/pt.c (revision 218857) +++ cp/pt.c (working copy) @@ -14438,16 +14438,6 @@ tsubst_non_call_postfix_expression (tree t, tree a return t; } -/* Sentinel to disable certain warnings during template substitution. */ - -struct warning_sentinel { - int &flag; - int val; - warning_sentinel(int& flag, bool suppress=true) - : flag(flag), val(flag) { if (suppress) flag = 0; } - ~warning_sentinel() { flag = val; } -}; - /* Like tsubst but deals with expressions and performs semantic analysis. FUNCTION_P is true if T is the "F" in "F (ARGS)". */ Index: cp/semantics.c =================================================================== --- cp/semantics.c (revision 218857) +++ cp/semantics.c (working copy) @@ -1660,6 +1660,7 @@ force_paren_expr (tree expr) tree type = unlowered_expr_type (expr); bool rval = !!(kind & clk_rvalueref); type = cp_build_reference_type (type, rval); + warning_sentinel s (extra_warnings); expr = build_static_cast (type, expr, tf_error); if (expr != error_mark_node) REF_PARENTHESIZED_P (expr) = true; Index: testsuite/g++.dg/warn/register-parm-1.C =================================================================== --- testsuite/g++.dg/warn/register-parm-1.C (revision 0) +++ testsuite/g++.dg/warn/register-parm-1.C (working copy) @@ -0,0 +1,9 @@ +// PR c++/60955 +// { dg-options "-Wextra" } + +unsigned int erroneous_warning(register int a) { + if ((a) & 0xff) return 1; else return 0; +} +unsigned int no_erroneous_warning(register int a) { + if (a & 0xff) return 1; else return 0; +}