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.
//////////////////////
/cp
2011-11-09 Paolo Carlini <paolo.carl...@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.carl...@oracle.com>
PR c++/51045
* g++.dg/warn/Wzero-as-null-pointer-constant-2.C: New.
2011-11-09 Paolo Carlini <paolo.carl...@oracle.com>
* doc/invoke.texi ([Option Summary, C++ Language Options]):
Add -Wzero-as-null-pointer-constant.
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;