This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/52988 (omitted calls with nullptr)


We were assuming that any expression of nullptr_t was equivalent to nullptr, but that isn't valid if the expression has side-effects...

Tested x86_64-pc-linux-gnu, applying to 4.6, 4.7, trunk.
commit c716e8680864db1312338691de7d2618efec1c3f
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jun 25 13:06:15 2012 -0400

    	PR c++/52988
    	* typeck.c (decay_conversion): Don't discard side-effects from
    	expressions of nullptr_t.

diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 945266b..971f386 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -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.
diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr28.C b/gcc/testsuite/g++.dg/cpp0x/nullptr28.C
new file mode 100644
index 0000000..05fbe57
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nullptr28.C
@@ -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 ();
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]