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

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

Hi,

apparently, in my -Wzero-as-null-pointer-constant I forgot to check the 
NE_EXPR we are synthesizing upon new and delete, thus these spurious 
warnings (I beefed up the original testcase to exercise the vector case 
too). The fix seems largely obvious, just use nullptr_node more, but I 
would ask you the courtesy to pay a particular attention to the second 
hunk below: close to the integer_zero_node I'm touching, there are a 
couple of other integer_zero_node...

Tested x86_64-linux.

Thanks,
Paolo.

PS: I'm taking the occasion to also add the new warning to the C++ 
summary in the docs. PPS: I think Jon has a similar patch already posted 
on the ml.

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

[-- Attachment #2: CL_51045 --]
[-- Type: text/plain, Size: 445 bytes --]

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

	PR c++/51045
	* init.c (build_new_1, build_vec_delete_1, build_delete):
	Use nullptr_node.

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

	PR c++/51045
	* g++.dg/warn/Wzero-as-null-pointer-constant-2.C: New.


2011-11-09  Paolo Carlini  <paolo.carlini@oracle.com>

	* doc/invoke.texi ([Option Summary, C++ Language Options]):
	Add -Wzero-as-null-pointer-constant.


[-- Attachment #3: patch_51045 --]
[-- Type: text/plain, Size: 2520 bytes --]

Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi	(revision 181201)
+++ doc/invoke.texi	(working copy)
@@ -200,7 +200,7 @@ in the following sections.
 -Weffc++  -Wstrict-null-sentinel @gol
 -Wno-non-template-friend  -Wold-style-cast @gol
 -Woverloaded-virtual  -Wno-pmf-conversions @gol
--Wsign-promo}
+-Wsign-promo -Wzero-as-null-pointer-constant}
 
 @item Objective-C and Objective-C++ Language Options
 @xref{Objective-C and Objective-C++ Dialect Options,,Options Controlling
Index: testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-2.C
===================================================================
--- testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-2.C	(revision 0)
+++ testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-2.C	(revision 0)
@@ -0,0 +1,49 @@
+// PR c++/51045
+// { dg-options "-Wzero-as-null-pointer-constant" }
+
+template <typename T>
+struct A
+{
+  A() { t = new T; }
+
+  ~A()
+  {
+    delete t;
+  }
+  T* t;
+};
+
+template <typename T>
+struct B
+{
+  B() { t = new T[1]; }
+
+  ~B()
+  {
+    delete [] t;
+  }
+  T* t;
+};
+
+template <typename Type>
+class Variant
+{
+  Type t;
+};
+
+class Op;
+
+typedef Variant<A<Op> > vara;
+typedef Variant<B<Op> > varb;
+
+class Op
+{
+  vara x;
+  varb y;
+};
+
+int main()
+{
+  vara a;
+  varb b;
+}
Index: cp/init.c
===================================================================
--- cp/init.c	(revision 181201)
+++ cp/init.c	(working copy)
@@ -2646,7 +2646,7 @@ build_new_1 (VEC(tree,gc) **placement, tree type,
 	{
 	  tree ifexp = cp_build_binary_op (input_location,
 					   NE_EXPR, alloc_node,
-					   integer_zero_node,
+					   nullptr_node,
 					   complain);
 	  rval = build_conditional_expr (ifexp, rval, alloc_node, 
                                          complain);
@@ -2958,7 +2958,7 @@ build_vec_delete_1 (tree base, tree maxindex, tree
 		      fold_build2_loc (input_location,
 				   NE_EXPR, boolean_type_node, base,
 				   convert (TREE_TYPE (base),
-					    integer_zero_node)),
+					    nullptr_node)),
 		      body, integer_zero_node);
   body = build1 (NOP_EXPR, void_type_node, body);
 
@@ -3685,7 +3685,7 @@ build_delete (tree type, tree addr, special_functi
 	{
 	  /* Handle deleting a null pointer.  */
 	  ifexp = fold (cp_build_binary_op (input_location,
-					    NE_EXPR, addr, integer_zero_node,
+					    NE_EXPR, addr, nullptr_node,
 					    complain));
 	  if (ifexp == error_mark_node)
 	    return error_mark_node;

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

* Re: [C++ Patch] PR 51045
  2011-11-09 13:58 [C++ Patch] PR 51045 Paolo Carlini
@ 2011-11-09 17:16 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2011-11-09 17:16 UTC (permalink / raw)
  To: Paolo Carlini; +Cc: gcc-patches

OK.

Jason

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

end of thread, other threads:[~2011-11-09 17:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-09 13:58 [C++ Patch] PR 51045 Paolo Carlini
2011-11-09 17:16 ` 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).