diff mbox

[C++] PR 51299

Message ID 4ED675DB.6080302@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Nov. 30, 2011, 6:28 p.m. UTC
On 11/30/2011 06:27 PM, Jason Merrill wrote:
> 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.
Ah, thanks a lot, much better. The below is what I'm going to apply.

Paolo.

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

	PR c++/51299
	* rtti.c (ifnonnull): Use nullptr_node.
	(build_dynamic_cast_1): Call cp_truthvalue_conversion instead
	of c_common_truthvalue_conversion.

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

	PR c++/51299
	* g++.dg/warn/Wzero-as-null-pointer-constant-4.C: New.
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 181853)
+++ 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,7 @@  build_dynamic_cast_1 (tree type, tree expr, tsubst
 	      tree neq;
 
 	      result = save_expr (result);
-	      neq = c_common_truthvalue_conversion (input_location, result);
+	      neq = cp_truthvalue_conversion (result);
 	      return cp_convert (type,
 				 build3 (COND_EXPR, TREE_TYPE (result),
 					 neq, result, bad));