OSDN Git Service

Add support for C++0x nullptr.
[pf3gnuchains/gcc-fork.git] / gcc / cp / call.c
index e8fcc94..d74eb19 100644 (file)
@@ -460,9 +460,11 @@ null_ptr_cst_p (tree t)
   /* [conv.ptr]
 
      A null pointer constant is an integral constant expression
-     (_expr.const_) rvalue of integer type that evaluates to zero.  */
+     (_expr.const_) rvalue of integer type that evaluates to zero or
+     an rvalue of type std::nullptr_t. */
   t = integral_constant_value (t);
-  if (t == null_node)
+  if (t == null_node
+      || TREE_CODE (TREE_TYPE (t)) == NULLPTR_TYPE)
     return true;
   if (CP_INTEGRAL_TYPE_P (TREE_TYPE (t)) && integer_zerop (t))
     {
@@ -776,7 +778,12 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
   if (same_type_p (from, to))
     return conv;
 
-  if ((tcode == POINTER_TYPE || TYPE_PTR_TO_MEMBER_P (to))
+  /* [conv.ptr]
+     A null pointer constant can be converted to a pointer type; ... A
+     null pointer constant of integral type can be converted to an
+     rvalue of type std::nullptr_t. */
+  if ((tcode == POINTER_TYPE || TYPE_PTR_TO_MEMBER_P (to)
+       || tcode == NULLPTR_TYPE)
       && expr && null_ptr_cst_p (expr))
     conv = build_conv (ck_std, to, conv);
   else if ((tcode == INTEGER_TYPE && fcode == POINTER_TYPE)
@@ -911,17 +918,20 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
 
          An rvalue of arithmetic, unscoped enumeration, pointer, or
          pointer to member type can be converted to an rvalue of type
-         bool.  */
+         bool. ... An rvalue of type std::nullptr_t can be converted
+         to an rvalue of type bool;  */
       if (ARITHMETIC_TYPE_P (from)
          || UNSCOPED_ENUM_P (from)
          || fcode == POINTER_TYPE
-         || TYPE_PTR_TO_MEMBER_P (from))
+         || TYPE_PTR_TO_MEMBER_P (from)
+         || fcode == NULLPTR_TYPE)
        {
          conv = build_conv (ck_std, to, conv);
          if (fcode == POINTER_TYPE
              || TYPE_PTRMEM_P (from)
              || (TYPE_PTRMEMFUNC_P (from)
-                 && conv->rank < cr_pbool))
+                 && conv->rank < cr_pbool)
+              || fcode == NULLPTR_TYPE)
            conv->rank = cr_pbool;
          return conv;
        }
@@ -5192,6 +5202,8 @@ convert_arg_to_ellipsis (tree arg)
          < TYPE_PRECISION (double_type_node))
       && !DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (arg))))
     arg = convert_to_real (double_type_node, arg);
+  else if (TREE_CODE (TREE_TYPE (arg)) == NULLPTR_TYPE)
+    arg = null_pointer_node;
   else if (INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (arg)))
     arg = perform_integral_promotions (arg);
 
@@ -6788,9 +6800,8 @@ compare_ics (conversion *ics1, conversion *ics2)
     Two conversion sequences with the same rank are indistinguishable
     unless one of the following rules applies:
 
-    --A conversion that is not a conversion of a pointer, or pointer
-      to member, to bool is better than another conversion that is such
-      a conversion.
+    --A conversion that does not a convert a pointer, pointer to member,
+      or std::nullptr_t to bool is better than one that does.
 
     The ICS_STD_RANK automatically handles the pointer-to-bool rule,
     so that we do not have to check it explicitly.  */