From patchwork Sun Oct 9 12:13:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 118586 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 A926DB70C2 for ; Sun, 9 Oct 2011 23:15:46 +1100 (EST) Received: (qmail 31919 invoked by alias); 9 Oct 2011 12:15:38 -0000 Received: (qmail 31909 invoked by uid 22791); 9 Oct 2011 12:15:35 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from acsinet15.oracle.com (HELO acsinet15.oracle.com) (141.146.126.227) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 09 Oct 2011 12:15:13 +0000 Received: from ucsinet24.oracle.com (ucsinet24.oracle.com [156.151.31.67]) by acsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id p99CFAn9013140 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Sun, 9 Oct 2011 12:15:12 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by ucsinet24.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p99C9GVD021805 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 9 Oct 2011 12:09:16 GMT Received: from abhmt106.oracle.com (abhmt106.oracle.com [141.146.116.58]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p99CF4F6015166; Sun, 9 Oct 2011 07:15:04 -0500 Received: from [192.168.1.4] (/79.53.208.75) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 09 Oct 2011 05:15:04 -0700 Message-ID: <4E918FED.4060002@oracle.com> Date: Sun, 09 Oct 2011 14:13:33 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0) Gecko/20110922 Thunderbird/7.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 50660 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, another duplicated diagnostic message. This one happens for snippets like the below due to the temporary for the const ref: int g(const int&); int m2() { return g(__null); } 50660.C:4:18: warning: passing NULL to non-pointer argument 1 of ‘int g(const int&)’ 50660.C:4:18: warning: passing NULL to non-pointer argument 1 of ‘int g(const int&)’ I'm changing conversion_null_warnings to return true when a warning is actually produced, which is checked by convert_like_real before calling again itself recursively. I think it should be safe to shut down in that case all kinds of further warnings, otherwise, we could even envisage adding an issue_conversion_null_warnings parameter to convert_like_real, as a last resort which certainly works. Patch tested x86_64-linux. Thanks, Paolo. ///////////////////// 2011-10-09 Paolo Carlini PR c++/50660 * call.c (conversion_null_warnings): Return true when a warning is actually emitted. (convert_like_real): When conversion_null_warnings returns true set issue_conversion_warnings to false. Index: call.c =================================================================== --- call.c (revision 179720) +++ call.c (working copy) @@ -5509,9 +5509,9 @@ build_temp (tree expr, tree type, int flags, /* Perform warnings about peculiar, but valid, conversions from/to NULL. EXPR is implicitly converted to type TOTYPE. - FN and ARGNUM are used for diagnostics. */ + FN and ARGNUM are used for diagnostics. Returns true if warned. */ -static void +static bool conversion_null_warnings (tree totype, tree expr, tree fn, int argnum) { tree t = non_reference (totype); @@ -5526,6 +5526,7 @@ conversion_null_warnings (tree totype, tree expr, else warning_at (input_location, OPT_Wconversion_null, "converting to non-pointer type %qT from NULL", t); + return true; } /* Issue warnings if "false" is converted to a NULL pointer */ @@ -5538,7 +5539,9 @@ conversion_null_warnings (tree totype, tree expr, else warning_at (input_location, OPT_Wconversion_null, "converting % to pointer type %qT", t); + return true; } + return false; } /* Perform the conversions in CONVS on the expression EXPR. FN and @@ -5624,8 +5627,9 @@ convert_like_real (conversion *convs, tree expr, t return cp_convert (totype, expr); } - if (issue_conversion_warnings && (complain & tf_warning)) - conversion_null_warnings (totype, expr, fn, argnum); + if (issue_conversion_warnings && (complain & tf_warning) + && conversion_null_warnings (totype, expr, fn, argnum)) + issue_conversion_warnings = false; switch (convs->kind) {