From 7c0b157d7cd49c57b769726e6838359014512e73 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 13 May 2013 15:32:42 -0400 Subject: [PATCH] re PR c++/56998 (ICE in value_dependent_expression_p, at cp/pt.c:19598) PR c++/56998 * call.c (null_ptr_cst_p): An expression with side-effects can't be a C++03 null pointer constant. From-SVN: r198845 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/call.c | 2 +- gcc/testsuite/g++.dg/template/overload13.C | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/template/overload13.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 33c66e370f3..38b43d51d3e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2013-05-13 Jason Merrill + 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. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index bd8f531eea4..9f3a50d47d2 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -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 index 00000000000..d41ccd01a93 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/overload13.C @@ -0,0 +1,16 @@ +// PR c++/56998 + +class Secret; +char IsNullLiteralHelper(Secret* p); +char (&IsNullLiteralHelper(...))[2]; + +struct C +{ + int val() { return 42; } +}; + +template +unsigned f() +{ + return sizeof(IsNullLiteralHelper(C().val())); +} -- 2.30.2