This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Fix value initialized decltype(nullptr) in constexpr (PR c++/85553)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 27 Apr 2018 20:07:36 +0200
- Subject: [C++ PATCH] Fix value initialized decltype(nullptr) in constexpr (PR c++/85553)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
init = fold (convert (type, nullptr_node)); unfortunately creates
a NOP_EXPR around INTEGER_CST and constexpr.c doesn't consider that a valid
constant; fold (convert (type, integer_zero_node)) we used previously
on the other side emitted warnings.
The following patch just builds the INTEGER_CST directly.
Tested on x86_64-linux with make check-c++-all, ok for trunk and 8.1
if it passes full bootstrap/regtest on {x86_64,i686}-linux?
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.
* g++.dg/cpp0x/Wzero-as-null-pointer-constant-3.C: Add dg-bogus
directive.
* g++.dg/cpp0x/constexpr-85553.C: New test.
--- gcc/cp/init.c.jj 2018-04-27 19:11:56.613549524 +0200
+++ gcc/cp/init.c 2018-04-27 19:20:50.102839130 +0200
@@ -180,8 +180,10 @@ build_zero_init_1 (tree type, tree nelts
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)))
--- gcc/testsuite/g++.dg/cpp0x/Wzero-as-null-pointer-constant-3.C.jj 2018-04-12 10:22:56.640162364 +0200
+++ gcc/testsuite/g++.dg/cpp0x/Wzero-as-null-pointer-constant-3.C 2018-04-27 19:23:58.349941329 +0200
@@ -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" }
--- gcc/testsuite/g++.dg/cpp0x/constexpr-85553.C.jj 2018-04-27 19:24:33.547960437 +0200
+++ gcc/testsuite/g++.dg/cpp0x/constexpr-85553.C 2018-04-27 19:24:51.456970160 +0200
@@ -0,0 +1,4 @@
+// PR c++/85553
+// { dg-do compile { target c++11 } }
+using T = decltype(nullptr);
+const constexpr T foo{};
Jakub