From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 108597 invoked by alias); 23 Apr 2015 15:12:12 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 108583 invoked by uid 89); 23 Apr 2015 15:12:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 23 Apr 2015 15:12:11 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3NFC9Hl011773 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 23 Apr 2015 11:12:09 -0400 Received: from [10.10.116.45] ([10.10.116.45]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3NFC951032725; Thu, 23 Apr 2015 11:12:09 -0400 Message-ID: <55390BC4.9000403@redhat.com> Date: Thu, 23 Apr 2015 15:12:00 -0000 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Emit -Waddress warnings for comparing address of reference against NULL References: <1429583806-29631-1-git-send-email-patrick@parcs.ath.cx> In-Reply-To: <1429583806-29631-1-git-send-email-patrick@parcs.ath.cx> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2015-04/txt/msg01422.txt.bz2 On 04/20/2015 10:36 PM, Patrick Palka wrote: > + if (decl_with_nonnull_addr_p (inner)) Using decl_with_nonnull_addr_p doesn't make sense for reference variables, since we're using their pointer value rather than their address. > + warning_at (location, > + OPT_Waddress, > + "the address of reference %qD may be assumed to " > + "always evaluate to %", > + inner); Perhaps "the compiler can assume that the address of reference %qD will always evaluate to %"? > - if (TREE_CODE (op0) == ADDR_EXPR > + if ((TREE_CODE (op0) == ADDR_EXPR > + || (CONVERT_EXPR_P (op0) > + && TREE_CODE (TREE_TYPE (TREE_OPERAND (op0, 0))) > + == REFERENCE_TYPE)) > && decl_with_nonnull_addr_p (TREE_OPERAND (op0, 0))) > { > if ((complain & tf_warning) > @@ -4437,7 +4440,10 @@ cp_build_binary_op (location_t location, > else > result_type = type1; > > - if (TREE_CODE (op1) == ADDR_EXPR > + if ((TREE_CODE (op1) == ADDR_EXPR > + || (CONVERT_EXPR_P (op1) > + && TREE_CODE (TREE_TYPE (TREE_OPERAND (op1, 0))) > + == REFERENCE_TYPE)) Let's distinguish between address of object vs reference in these warnings, too. Jason