Hi,

On 11/26/2014 05:24 PM, Jason Merrill wrote:
On 11/24/2014 01:55 PM, Paolo Carlini wrote:
in this rejects-valid, as part of build_user_type_conversion_1,
standard_conversion is called by implicit_conversion with a *null* expr,
thus the condition in standard_conversion

   /* [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_PTRMEM_P (to)
        || NULLPTR_TYPE_P (to))
       && expr && null_ptr_cst_p (expr))
     conv = build_conv (ck_std, to, conv);

is false and the snippet is rejected. Should we pass a nullptr_node as
expr in such cases, ie, when handling conversions functions returning
std::nullptr_t?!?

I'd prefer to change the test quoted above to not require expr to be non-null in the case of NULLPTR_TYPE_P.
Oh good, I was unsure about that. The below also passes testing.

Thanks,
Paolo.

///////////////////////////
Index: cp/call.c
===================================================================
--- cp/call.c   (revision 218089)
+++ cp/call.c   (working copy)
@@ -1194,7 +1194,8 @@ standard_conversion (tree to, tree from, tree expr
      rvalue of type std::nullptr_t. */
   if ((tcode == POINTER_TYPE || TYPE_PTRMEM_P (to)
        || NULLPTR_TYPE_P (to))
-      && expr && null_ptr_cst_p (expr))
+      && ((expr && null_ptr_cst_p (expr))
+         || NULLPTR_TYPE_P (from)))
     conv = build_conv (ck_std, to, conv);
   else if ((tcode == INTEGER_TYPE && fcode == POINTER_TYPE)
           || (tcode == POINTER_TYPE && fcode == INTEGER_TYPE))
Index: testsuite/g++.dg/cpp0x/nullptr33.C
===================================================================
--- testsuite/g++.dg/cpp0x/nullptr33.C  (revision 0)
+++ testsuite/g++.dg/cpp0x/nullptr33.C  (working copy)
@@ -0,0 +1,19 @@
+// PR c++/63757
+// { dg-do compile { target c++11 } }
+
+typedef decltype(nullptr) nullptr_t;
+
+void bar(void*) {}
+ 
+struct foo
+{
+  operator nullptr_t()
+  {
+    return nullptr;
+  }
+};
+
+int main()
+{
+  bar(foo());
+}

Reply via email to