re PR c++/51045 (erroneous zero as null pointer constant warning at delete)

/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.

From-SVN: r181214
This commit is contained in:
Paolo Carlini 2011-11-09 17:21:19 +00:00 committed by Paolo Carlini
parent db422ace3f
commit 6d96d7ff5e
5 changed files with 83 additions and 4 deletions

View File

@ -1,3 +1,8 @@
2011-11-09 Paolo Carlini <paolo.carlini@oracle.com>
* doc/invoke.texi ([Option Summary, C++ Language Options]):
Add -Wzero-as-null-pointer-constant.
2011-11-07 Matthew Gretton-Dann <matthew.gretton-dann@arm.com>
* config/arm/arm-cores.def: Add -mcpu=cortex-a7.

View File

@ -1,3 +1,28 @@
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.
2011-11-09 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/51047
* search.c (lookup_member): Change to take also a tsubst_flags_t
parameter.
(lookup_field, lookup_fnfields): Adjust calls.
* typeck.c (lookup_destructor, finish_class_member_access_expr,
build_ptrmemfunc_access_expr): Likewise.
* class.c (handle_using_decl, maybe_note_name_used_in_class):
Likewise.
* pt.c (resolve_typename_type): Likewise.
* semantics.c (lambda_function): Likewise.
* parser.c (cp_parser_perform_range_for_lookup,
cp_parser_lookup_name): Likewise.
* friend.c (make_friend_class): Likewise.
* name-lookup.c (pushdecl_maybe_friend_1, get_class_binding,
do_class_using_decl, lookup_qualified_name): Likewise.
* cp-tree.h (lookup_member): Adjust declaration.
2011-11-09 Dodji Seketeli <dodji@redhat.com>
PR c++/51027

View File

@ -2646,7 +2646,7 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts,
{
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 type,
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_function_kind auto_delete,
{
/* 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;

View File

@ -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

View File

@ -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;
}