diff mbox

[C++] PR 51299

Message ID 4ECF1AD5.1070600@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Nov. 25, 2011, 4:34 a.m. UTC
Hi,

more spurious -Wzero-as-null.. warnings, this one is about 
dynamic_casts, which I completely overlooked. In order to fix the 
original testcase, which involves pointers, it's enough to use 
nullptr_node in ifnnonnull; in order to fix a version I added for 
references, we have to use here too the c_inhibit_evaluation_warnings 
trick, because result in that case, a SAVE_EXPR, is of type POINTER_TYPE.

Tested x86_64-linux, Ok?

Thanks,
Paolo.

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

	PR c++/51299
	* rtti.c (ifnonnull): Use nullptr_node.
	(build_dynamic_cast_1): Inhibit evaluation warnings for the
	c_common_truthvalue_conversion call.

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

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

Comments

Jason Merrill Nov. 30, 2011, 5:27 p.m. UTC | #1
On 11/24/2011 11:34 PM, Paolo Carlini wrote:
> +	      /* Avoid -Wzero-as-null-pointer-constant warnings.  */
> +	      ++c_inhibit_evaluation_warnings;
>   	      neq = c_common_truthvalue_conversion (input_location, result);
> +	      --c_inhibit_evaluation_warnings;

How about using cp_truthvalue_conversion here?  OK with that change.

Jason
diff mbox

Patch

Index: testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-4.C
===================================================================
--- testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-4.C	(revision 0)
+++ testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-4.C	(revision 0)
@@ -0,0 +1,22 @@ 
+// PR c++/51299
+// { dg-options "-Wzero-as-null-pointer-constant" }
+
+class Base
+{
+  public:
+  virtual ~Base();
+};
+
+class Derived : public Base
+{
+};
+
+void foo(Base* b)
+{
+  Derived* d = dynamic_cast<Derived*>(b);
+}
+
+void bar(Base& b)
+{
+  Derived& d = dynamic_cast<Derived&>(b);
+}
Index: cp/rtti.c
===================================================================
--- cp/rtti.c	(revision 181706)
+++ cp/rtti.c	(working copy)
@@ -503,8 +503,8 @@  ifnonnull (tree test, tree result)
 {
   return build3 (COND_EXPR, TREE_TYPE (result),
 		 build2 (EQ_EXPR, boolean_type_node, test,
-			 cp_convert (TREE_TYPE (test), integer_zero_node)),
-		 cp_convert (TREE_TYPE (result), integer_zero_node),
+			 cp_convert (TREE_TYPE (test), nullptr_node)),
+		 cp_convert (TREE_TYPE (result), nullptr_node),
 		 result);
 }
 
@@ -747,7 +747,10 @@  build_dynamic_cast_1 (tree type, tree expr, tsubst
 	      tree neq;
 
 	      result = save_expr (result);
+	      /* Avoid -Wzero-as-null-pointer-constant warnings.  */
+	      ++c_inhibit_evaluation_warnings;
 	      neq = c_common_truthvalue_conversion (input_location, result);
+	      --c_inhibit_evaluation_warnings;
 	      return cp_convert (type,
 				 build3 (COND_EXPR, TREE_TYPE (result),
 					 neq, result, bad));