re PR c++/52988 (std::async not executed on function returning nullptr_t)
authorJason Merrill <jason@redhat.com>
Mon, 25 Jun 2012 20:39:47 +0000 (16:39 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 25 Jun 2012 20:39:47 +0000 (16:39 -0400)
PR c++/52988
* typeck.c (decay_conversion): Don't discard side-effects from
expressions of nullptr_t.

From-SVN: r188955

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/nullptr28.C [new file with mode: 0644]

index fbaca5106c25508a270979a8570edcdeee1f287e..2d321b0005eb3aeeded3172c7cec3b7eeaf2c586 100644 (file)
@@ -1,3 +1,9 @@
+2012-06-25  Jason Merrill  <jason@redhat.com>
+
+       PR c++/52988
+       * typeck.c (decay_conversion): Don't discard side-effects from
+       expressions of nullptr_t.
+
 2012-06-25  Florian Weimer  <fweimer@redhat.com>
 
        * init.c (build_new_1): Warn about (T[N]) for variable N, and
index 945266b854e9f42349f4c27bb8e1c31030e781f8..971f386e56f05de2ca3cf88016c2dfc468a1459a 100644 (file)
@@ -1843,7 +1843,7 @@ decay_conversion (tree exp, tsubst_flags_t complain)
   if (error_operand_p (exp))
     return error_mark_node;
 
-  if (NULLPTR_TYPE_P (type))
+  if (NULLPTR_TYPE_P (type) && !TREE_SIDE_EFFECTS (exp))
     return nullptr_node;
 
   /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue.
index 30b83d5b6d58d5ba82e936b4614941d28fb92826..0323f99f212145bfc856d6bbbe6b98b7bda5b113 100644 (file)
@@ -1,3 +1,8 @@
+2012-06-25  Jason Merrill  <jason@redhat.com>
+
+       PR c++/52988
+       * g++.dg/cpp0x/nullptr28.C: New.
+
 2012-06-25  Christophe Lyon  <christophe.lyon@st.com>
 
        * gcc.target/arm/neon-vld1_dupQ.c: New.
diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr28.C b/gcc/testsuite/g++.dg/cpp0x/nullptr28.C
new file mode 100644 (file)
index 0000000..05fbe57
--- /dev/null
@@ -0,0 +1,16 @@
+// { dg-do run { target c++11 } }
+
+typedef decltype(nullptr) nullptr_t;
+
+int i;
+nullptr_t n;
+const nullptr_t& f() { ++i; return n; }
+
+nullptr_t g() { return f(); }
+
+int main()
+{
+  g();
+  if (i != 1)
+    __builtin_abort ();
+}