Hi,
this isn't a regression, but deciding what we want to do should be easy
and quick enough. The issue is that "mysteriously" we warn
-Wzero-as-null-pointer-constant for:
decltype( nullptr ) warn = {};
and we don't for:
int* no_warn = {};
That's easily explained given the code we have in build_zero_init_1
which handles types satisfying TYPE_PTR_OR_PTRMEM_P separately from all
the other scalar types, std::nullptr_t included. I think we should
resolve the inconsistency - the below does that without regressions -
but frankly, at first, given the letter of the standard under 11.6/6
about zero-initialization I expected that we weren't handling types
satisfying TYPE_PTR_OR_PTRMEM_P in a different way, thus something like
a sheer integer_zero_node consistently for all the scalars (which would
mean resolving the inconsistency precisely the other way round).
Probably it's a tricky detail of our internal representations...
Thanks, Paolo.
///////////////////
/cp
2018-04-10 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/70808
* init.c (build_zero_init_1): Handle NULLPTR_TYPE_P being true of
the type like TYPE_PTR_OR_PTRMEM_P.
/testsuite
2018-04-10 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/70808
* g++.dg/warn/Wzero-as-null-pointer-constant-7.C: New.
Index: cp/init.c
===================================================================
--- cp/init.c (revision 259287)
+++ cp/init.c (working copy)
@@ -180,7 +180,7 @@ build_zero_init_1 (tree type, tree nelts, bool sta
items with static storage duration that are not otherwise
initialized are initialized to zero. */
;
- else if (TYPE_PTR_OR_PTRMEM_P (type))
+ else if (TYPE_PTR_OR_PTRMEM_P (type) || NULLPTR_TYPE_P (type))
init = fold (convert (type, nullptr_node));
else if (SCALAR_TYPE_P (type))
init = fold (convert (type, integer_zero_node));
Index: testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-7.C
===================================================================
--- testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-7.C (nonexistent)
+++ testsuite/g++.dg/warn/Wzero-as-null-pointer-constant-7.C (working copy)
@@ -0,0 +1,5 @@
+// PR c++/70808
+// { dg-options "-Wzero-as-null-pointer-constant" }
+
+int* no_warn = {};
+decltype( nullptr ) warn = {};