diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d8e7089af85..6253c9b91a0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-04-27 Jakub Jelinek + + PR c++/85553 + * init.c (build_zero_init_1): For zero initialization of + NULLPTR_TYPE_P type use build_int_cst directly. + 2018-04-27 David Malcolm PR c++/85515 diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 52a927e4600..d6c0bcf8ce3 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -180,8 +180,10 @@ build_zero_init_1 (tree type, tree nelts, bool static_storage_p, items with static storage duration that are not otherwise initialized are initialized to zero. */ ; - else if (TYPE_PTR_OR_PTRMEM_P (type) || NULLPTR_TYPE_P (type)) + else if (TYPE_PTR_OR_PTRMEM_P (type)) init = fold (convert (type, nullptr_node)); + else if (NULLPTR_TYPE_P (type)) + init = build_int_cst (type, 0); else if (SCALAR_TYPE_P (type)) init = fold (convert (type, integer_zero_node)); else if (RECORD_OR_UNION_CODE_P (TREE_CODE (type))) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ce5eabadb57..9002abf723f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2018-04-27 Jakub Jelinek + + PR c++/85553 + * g++.dg/cpp0x/Wzero-as-null-pointer-constant-3.C: Add dg-bogus + directive. + * g++.dg/cpp0x/constexpr-85553.C: New test. + 2018-04-27 David Malcolm PR c++/85515 diff --git a/gcc/testsuite/g++.dg/cpp0x/Wzero-as-null-pointer-constant-3.C b/gcc/testsuite/g++.dg/cpp0x/Wzero-as-null-pointer-constant-3.C index b03ec943b35..3e471aa2c93 100644 --- a/gcc/testsuite/g++.dg/cpp0x/Wzero-as-null-pointer-constant-3.C +++ b/gcc/testsuite/g++.dg/cpp0x/Wzero-as-null-pointer-constant-3.C @@ -3,4 +3,4 @@ // { dg-options "-Wzero-as-null-pointer-constant" } int* no_warn = {}; -decltype( nullptr ) warn = {}; +decltype( nullptr ) warn = {}; // { dg-bogus "zero as null pointer constant" } diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-85553.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-85553.C new file mode 100644 index 00000000000..3c6d3c4af04 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-85553.C @@ -0,0 +1,4 @@ +// PR c++/85553 +// { dg-do compile { target c++11 } } +using T = decltype(nullptr); +const constexpr T foo{};