OSDN Git Service

PR c++/52988
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 25 Jun 2012 20:37:25 +0000 (20:37 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 25 Jun 2012 20:37:25 +0000 (20:37 +0000)
* typeck.c (decay_conversion): Don't discard side-effects from
expressions of nullptr_t.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@188954 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 1517a53..b4588e7 100644 (file)
@@ -1,5 +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.
+
        PR c++/53202
        * semantics.c (build_data_member_initialization): Always keep
        initializer for empty base.
index 8628e83..76fc585 100644 (file)
@@ -1838,7 +1838,7 @@ decay_conversion (tree exp)
   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 163950d..67a5a77 100644 (file)
@@ -1,5 +1,8 @@
 2012-06-25  Jason Merrill  <jason@redhat.com>
 
+       PR c++/52988
+       * g++.dg/cpp0x/nullptr28.C: New.
+
        PR c++/53202
        * g++.dg/cpp0x/constexpr-tuple.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 ();
+}