From b2b1ea3455979699f172e1601785efa57e3cd3f2 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 27 Apr 2018 22:29:12 +0200 Subject: [PATCH] re PR c++/85553 (cannot list-initialize a variable of type std::nullptr_t) PR c++/85553 * init.c (build_zero_init_1): For zero initialization of NULLPTR_TYPE_P type use build_int_cst directly. * g++.dg/cpp0x/Wzero-as-null-pointer-constant-3.C: Add dg-bogus directive. * g++.dg/cpp0x/constexpr-85553.C: New test. From-SVN: r259728 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/init.c | 4 +++- gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/g++.dg/cpp0x/Wzero-as-null-pointer-constant-3.C | 2 +- gcc/testsuite/g++.dg/cpp0x/constexpr-85553.C | 4 ++++ 5 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-85553.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d8e7089..6253c9b 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 52a927e..d6c0bcf 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 ce5eaba..9002abf 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 b03ec94..3e471aa 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 0000000..3c6d3c4 --- /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{}; -- 2.7.4