re PR c++/85553 (cannot list-initialize a variable of type std::nullptr_t)
authorJakub Jelinek <jakub@redhat.com>
Fri, 27 Apr 2018 20:29:12 +0000 (22:29 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 27 Apr 2018 20:29:12 +0000 (22:29 +0200)
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
gcc/cp/init.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/Wzero-as-null-pointer-constant-3.C
gcc/testsuite/g++.dg/cpp0x/constexpr-85553.C [new file with mode: 0644]

index d8e7089af859d94313acb5a602844f21e5040f23..6253c9b91a0c3487109135c31ba6395ccc355aaa 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-27  Jakub Jelinek  <jakub@redhat.com>
+
+       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  <dmalcolm@redhat.com>
 
        PR c++/85515
index 52a927e46004c328a1752a83daeeb49e600b49df..d6c0bcf8ce39bb4a4dab45e736e6ea59412d1efd 100644 (file)
@@ -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)))
index ce5eabadb5749924621cd535eae5f66980faee33..9002abf723fef608eeaa7e082ecaf464a102f460 100644 (file)
@@ -1,3 +1,10 @@
+2018-04-27  Jakub Jelinek  <jakub@redhat.com>
+
+       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  <dmalcolm@redhat.com>
 
        PR c++/85515
index b03ec943b354c2072f260b3774c2fc94e88838f1..3e471aa2c939a79196af95df413cc9695820e2d5 100644 (file)
@@ -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 (file)
index 0000000..3c6d3c4
--- /dev/null
@@ -0,0 +1,4 @@
+// PR c++/85553
+// { dg-do compile { target c++11 } }
+using T = decltype(nullptr);
+const constexpr T foo{};