PR c++/56998
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 13 May 2013 19:32:42 +0000 (19:32 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 13 May 2013 19:32:42 +0000 (19:32 +0000)
* call.c (null_ptr_cst_p): An expression with side-effects can't
be a C++03 null pointer constant.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@198845 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/g++.dg/template/overload13.C [new file with mode: 0644]

index 33c66e3..38b43d5 100644 (file)
@@ -1,5 +1,9 @@
 2013-05-13  Jason Merrill  <jason@redhat.com>
 
+       PR c++/56998
+       * call.c (null_ptr_cst_p): An expression with side-effects can't
+       be a C++03 null pointer constant.
+
        PR c++/57041
        * decl.c (reshape_init_class): Handle error_mark_node.
 
index bd8f531..9f3a50d 100644 (file)
@@ -554,7 +554,7 @@ null_ptr_cst_p (tree t)
   if (CP_INTEGRAL_TYPE_P (TREE_TYPE (t)))
     {
       /* Core issue 903 says only literal 0 is a null pointer constant.  */
-      if (cxx_dialect < cxx0x)
+      if (cxx_dialect < cxx0x && !TREE_SIDE_EFFECTS (t))
        t = maybe_constant_value (fold_non_dependent_expr_sfinae (t, tf_none));
       STRIP_NOPS (t);
       if (integer_zerop (t) && !TREE_OVERFLOW (t))
diff --git a/gcc/testsuite/g++.dg/template/overload13.C b/gcc/testsuite/g++.dg/template/overload13.C
new file mode 100644 (file)
index 0000000..d41ccd0
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/56998
+
+class Secret;
+char IsNullLiteralHelper(Secret* p);
+char (&IsNullLiteralHelper(...))[2];
+
+struct C
+{
+  int val() { return 42; }
+};
+
+template <typename T>
+unsigned f()
+{
+  return sizeof(IsNullLiteralHelper(C().val()));
+}