public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] PR 45278
@ 2011-09-28 21:47 Paolo Carlini
  2011-09-28 22:11 ` Paolo Carlini
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Carlini @ 2011-09-28 21:47 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

Hi,

here submitter remarks that, inconsistently with the documentation, with 
-Wextra the C++ front-end doesn't warn for ordered comparison of pointer 
with integer zero. Thus I simply adapted the warning in the C front-end. 
Is the patch Ok?

Tested x86_64-linux.

Paolo.

/////////////////

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [C++ Patch] PR 45278
  2011-09-28 21:47 [C++ Patch] PR 45278 Paolo Carlini
@ 2011-09-28 22:11 ` Paolo Carlini
  2011-09-28 22:45   ` Jason Merrill
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Carlini @ 2011-09-28 22:11 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 338 bytes --]

On 09/28/2011 11:02 PM, Paolo Carlini wrote:
> Hi,
>
> here submitter remarks that, inconsistently with the documentation, 
> with -Wextra the C++ front-end doesn't warn for ordered comparison of 
> pointer with integer zero. Thus I simply adapted the warning in the C 
> front-end. Is the patch Ok?
Better attaching the patch ;)

Paolo.

[-- Attachment #2: CL_45278 --]
[-- Type: text/plain, Size: 286 bytes --]

/cp
2011-09-28  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/45278
	* typeck.c (cp_build_binary_op): With -Wextra, warn for ordered
	comparison of pointer with zero.

/testsuite
2011-09-28  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/45278
	* g++.dg/warn/Wextra-3.C: New.


[-- Attachment #3: patch_45278 --]
[-- Type: text/plain, Size: 1612 bytes --]

Index: testsuite/g++.dg/warn/Wextra-3.C
===================================================================
--- testsuite/g++.dg/warn/Wextra-3.C	(revision 0)
+++ testsuite/g++.dg/warn/Wextra-3.C	(revision 0)
@@ -0,0 +1,9 @@
+// PR c++/45278
+// { dg-options "-Wextra" } 
+
+extern void* p;
+
+int f1() { return ( p <  0 ? 1 : 0 ); } // { dg-warning "ordered comparison" }
+int f2() { return ( p <= 0 ? 1 : 0 ); } // { dg-warning "ordered comparison" }
+int f3() { return ( p >  0 ? 1 : 0 ); } // { dg-warning "ordered comparison" }
+int f4() { return ( p >= 0 ? 1 : 0 ); } // { dg-warning "ordered comparison" }
Index: cp/typeck.c
===================================================================
--- cp/typeck.c	(revision 179319)
+++ cp/typeck.c	(working copy)
@@ -4189,9 +4189,19 @@ cp_build_binary_op (location_t location,
 	result_type = composite_pointer_type (type0, type1, op0, op1,
 					      CPO_COMPARISON, complain);
       else if (code0 == POINTER_TYPE && null_ptr_cst_p (op1))
-	result_type = type0;
+	{
+	  result_type = type0;
+	  if (extra_warnings && (complain & tf_warning))
+	    warning (OPT_Wextra,
+		     "ordered comparison of pointer with integer zero");
+	}
       else if (code1 == POINTER_TYPE && null_ptr_cst_p (op0))
-	result_type = type1;
+	{
+	  result_type = type1;
+	  if (extra_warnings && (complain & tf_warning))
+	    warning (OPT_Wextra,
+		     "ordered comparison of pointer with integer zero");
+	}
       else if (null_ptr_cst_p (op0) && null_ptr_cst_p (op1))
 	/* One of the operands must be of nullptr_t type.  */
         result_type = TREE_TYPE (nullptr_node);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [C++ Patch] PR 45278
  2011-09-28 22:11 ` Paolo Carlini
@ 2011-09-28 22:45   ` Jason Merrill
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2011-09-28 22:45 UTC (permalink / raw)
  To: Paolo Carlini; +Cc: gcc-patches

OK.

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-09-28 21:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-28 21:47 [C++ Patch] PR 45278 Paolo Carlini
2011-09-28 22:11 ` Paolo Carlini
2011-09-28 22:45   ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).