[C++ Patch] Fixes for duplicate warnings regressions [2/2]

Paolo Carlini paolo.carlini@oracle.com
Sun Nov 10 11:49:00 GMT 2013


Hi,

this is another issue, with -Wzero-as-null-pointer-constant, caused (or, 
better, exposed) by the fix for c++/54170: the problem is that 
build_ptrmemfunc, called by cp_convert_to_pointer, itself eventually 
calls cp_convert_to_pointer.

The build_ptrmemfunc bit isn't essential: using the cp_* variant of 
build_c_cast, which takes a tsubst_flags_t, in a function taking a 
tsubst_flags_t seems the right thing to do.

Tested x86_64-linux.

Thanks!
Paolo.

//////////////////////
-------------- next part --------------
2013-11-11  Paolo Carlini  <paolo.carlini@oracle.com>

	* cvt.c (cp_convert_to_pointer): Call build_ptrmemfunc before
	maybe_warn_zero_as_null_pointer_constant to avoid duplicate
	-Wzero-as-null-pointer-constant diagnostics.

	* typeck.c (build_ptrmemfunc): Use cp_build_c_cast.
-------------- next part --------------
Index: cp/cvt.c
===================================================================
--- cp/cvt.c	(revision 204620)
+++ cp/cvt.c	(working copy)
@@ -203,13 +203,13 @@ cp_convert_to_pointer (tree type, tree expr, tsubs
 
   if (null_ptr_cst_p (expr))
     {
-      if (complain & tf_warning)
-	maybe_warn_zero_as_null_pointer_constant (expr, loc);
-
       if (TYPE_PTRMEMFUNC_P (type))
 	return build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr, 0,
 				 /*c_cast_p=*/false, complain);
 
+      if (complain & tf_warning)
+	maybe_warn_zero_as_null_pointer_constant (expr, loc);
+
       /* A NULL pointer-to-data-member is represented by -1, not by
 	 zero.  */
       tree val = (TYPE_PTRDATAMEM_P (type)
Index: cp/typeck.c
===================================================================
--- cp/typeck.c	(revision 204620)
+++ cp/typeck.c	(working copy)
@@ -7779,7 +7781,7 @@ build_ptrmemfunc (tree type, tree pfn, int force,
   /* Handle null pointer to member function conversions.  */
   if (null_ptr_cst_p (pfn))
     {
-      pfn = build_c_cast (input_location, type, pfn);
+      pfn = cp_build_c_cast (type, pfn, complain);
       return build_ptrmemfunc1 (to_type,
 				integer_zero_node,
 				pfn);


More information about the Gcc-patches mailing list