* [Bug c++/94510] nullptr_t implicitly cast to zero twice in std::array
2020-04-07 8:23 [Bug c++/94510] New: nullptr_t implicitly cast to zero twice in std::array kndevl at outlook dot com
@ 2020-04-07 8:24 ` kndevl at outlook dot com
2020-04-07 8:24 ` kndevl at outlook dot com
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: kndevl at outlook dot com @ 2020-04-07 8:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94510
--- Comment #1 from Karthik Nishanth <kndevl at outlook dot com> ---
Created attachment 48218
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48218&action=edit
preprocessed source for bug.cpp
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/94510] nullptr_t implicitly cast to zero twice in std::array
2020-04-07 8:23 [Bug c++/94510] New: nullptr_t implicitly cast to zero twice in std::array kndevl at outlook dot com
2020-04-07 8:24 ` [Bug c++/94510] " kndevl at outlook dot com
@ 2020-04-07 8:24 ` kndevl at outlook dot com
2020-04-07 8:25 ` kndevl at outlook dot com
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: kndevl at outlook dot com @ 2020-04-07 8:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94510
--- Comment #2 from Karthik Nishanth <kndevl at outlook dot com> ---
Created attachment 48219
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48219&action=edit
bug.cpp
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/94510] nullptr_t implicitly cast to zero twice in std::array
2020-04-07 8:23 [Bug c++/94510] New: nullptr_t implicitly cast to zero twice in std::array kndevl at outlook dot com
2020-04-07 8:24 ` [Bug c++/94510] " kndevl at outlook dot com
2020-04-07 8:24 ` kndevl at outlook dot com
@ 2020-04-07 8:25 ` kndevl at outlook dot com
2020-04-07 8:25 ` kndevl at outlook dot com
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: kndevl at outlook dot com @ 2020-04-07 8:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94510
--- Comment #3 from Karthik Nishanth <kndevl at outlook dot com> ---
Created attachment 48220
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48220&action=edit
complete command line invocations
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/94510] nullptr_t implicitly cast to zero twice in std::array
2020-04-07 8:23 [Bug c++/94510] New: nullptr_t implicitly cast to zero twice in std::array kndevl at outlook dot com
` (2 preceding siblings ...)
2020-04-07 8:25 ` kndevl at outlook dot com
@ 2020-04-07 8:25 ` kndevl at outlook dot com
2020-04-07 8:26 ` kndevl at outlook dot com
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: kndevl at outlook dot com @ 2020-04-07 8:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94510
--- Comment #4 from Karthik Nishanth <kndevl at outlook dot com> ---
Created attachment 48221
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48221&action=edit
gcc version string
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/94510] nullptr_t implicitly cast to zero twice in std::array
2020-04-07 8:23 [Bug c++/94510] New: nullptr_t implicitly cast to zero twice in std::array kndevl at outlook dot com
` (3 preceding siblings ...)
2020-04-07 8:25 ` kndevl at outlook dot com
@ 2020-04-07 8:26 ` kndevl at outlook dot com
2020-04-07 8:30 ` kndevl at outlook dot com
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: kndevl at outlook dot com @ 2020-04-07 8:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94510
--- Comment #5 from Karthik Nishanth <kndevl at outlook dot com> ---
Created attachment 48222
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48222&action=edit
machine type
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/94510] nullptr_t implicitly cast to zero twice in std::array
2020-04-07 8:23 [Bug c++/94510] New: nullptr_t implicitly cast to zero twice in std::array kndevl at outlook dot com
` (4 preceding siblings ...)
2020-04-07 8:26 ` kndevl at outlook dot com
@ 2020-04-07 8:30 ` kndevl at outlook dot com
2020-04-07 8:30 ` kndevl at outlook dot com
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: kndevl at outlook dot com @ 2020-04-07 8:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94510
--- Comment #6 from Karthik Nishanth <kndevl at outlook dot com> ---
Created attachment 48223
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48223&action=edit
not a bug
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/94510] nullptr_t implicitly cast to zero twice in std::array
2020-04-07 8:23 [Bug c++/94510] New: nullptr_t implicitly cast to zero twice in std::array kndevl at outlook dot com
` (5 preceding siblings ...)
2020-04-07 8:30 ` kndevl at outlook dot com
@ 2020-04-07 8:30 ` kndevl at outlook dot com
2020-04-07 11:59 ` [Bug c++/94510] [9/10 Regression] " redi at gcc dot gnu.org
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: kndevl at outlook dot com @ 2020-04-07 8:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94510
--- Comment #7 from Karthik Nishanth <kndevl at outlook dot com> ---
Created attachment 48224
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48224&action=edit
not a bug, preprocessed
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/94510] [9/10 Regression] nullptr_t implicitly cast to zero twice in std::array
2020-04-07 8:23 [Bug c++/94510] New: nullptr_t implicitly cast to zero twice in std::array kndevl at outlook dot com
` (6 preceding siblings ...)
2020-04-07 8:30 ` kndevl at outlook dot com
@ 2020-04-07 11:59 ` redi at gcc dot gnu.org
2020-04-07 16:08 ` msebor at gcc dot gnu.org
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-07 11:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94510
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail| |10.0, 9.3.0
Known to work| |8.4.0
Last reconfirmed| |2020-04-07
Summary|nullptr_t implicitly cast |[9/10 Regression] nullptr_t
|to zero twice in std::array |implicitly cast to zero
| |twice in std::array
Ever confirmed|0 |1
Target Milestone|--- |9.4
Status|UNCONFIRMED |NEW
CC| |msebor at gcc dot gnu.org
--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Karthik Nishanth from comment #4)
> Created attachment 48221 [details]
> gcc version string
There's no need to create attachments for each tiny bit of text, comments are
fine, and much easier for us to see, without having to click through a separate
page. (Your attachment in comment 3 just duplicates what you already said in
comment 0 anyway!)
Relevant info from the comment 4 attachment:
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-pkgversion='Arch Linux 9.3.0-1'
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-shared
--enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-lto --enable-plugin --enable-install-libiberty
--with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib
--disable-werror --enable-checking=release --enable-default-pie
--enable-default-ssp --enable-cet=auto gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
gcc version 9.3.0 (Arch Linux 9.3.0-1)
Reduced testcase:
int arr[3] = { nullptr, 0, 0 };
This is a regression introduced by r270155
PR c++/89974 - ICE on a definition of a non-type specialization on a struct
object with pointer to member function
PR c++/89974 - ICE on a definition of a non-type specialization on a struct
object with pointer to member function
PR c++/89878 - same specializations on a zero-initialized struct object as
a non-type parameter treated as distinct
PR c++/89833 - sorry, unimplemented: string literal in function template
signature
PR c++/47488 - sorry, unimplemented: string literal in function template
signature
gcc/cp/ChangeLog:
PR c++/89974
PR c++/89878
PR c++/89833
PR c++/47488
* decl.c (reshape_init_array_1): Strip trailing zero-initializers
from arrays of trivial type and known size.
* mangle.c (write_expression): Convert braced initializer lists
to STRING_CSTs.
(write_expression): Trim trailing zero-initializers from arrays
of trivial type.
(write_template_arg_literal): Mangle strings the same as braced
initializer lists.
gcc/testsuite/ChangeLog:
PR c++/89974
PR c++/89878
PR c++/89833
PR c++/47488
* gcc/testsuite/g++.dg/abi/mangle69.C: New test.
* gcc/testsuite/g++.dg/abi/mangle70.C: New test.
* gcc/testsuite/g++.dg/abi/mangle71.C: New test.
* gcc/testsuite/g++.dg/abi/mangle72.C: New test.
* gcc/testsuite/g++.dg/cpp0x/constexpr-array19.C: New test.
* gcc/testsuite/g++.dg/cpp2a/nontype-class15.C: New test.
* gcc/testsuite/g++.dg/cpp2a/nontype-class16.C: New test.
* gcc/testsuite/g++.dg/init/array51.C: New test.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/94510] [9/10 Regression] nullptr_t implicitly cast to zero twice in std::array
2020-04-07 8:23 [Bug c++/94510] New: nullptr_t implicitly cast to zero twice in std::array kndevl at outlook dot com
` (7 preceding siblings ...)
2020-04-07 11:59 ` [Bug c++/94510] [9/10 Regression] " redi at gcc dot gnu.org
@ 2020-04-07 16:08 ` msebor at gcc dot gnu.org
2020-04-07 18:51 ` msebor at gcc dot gnu.org
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-04-07 16:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94510
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #9 from Martin Sebor <msebor at gcc dot gnu.org> ---
The changed code in reshape_init_array_1 checks for integer/pointer mismatches
via the following test:
/* Pointers initialized to strings must be treated as non-zero
even if the string is empty. */
tree init_type = TREE_TYPE (elt_init);
if (POINTER_TYPE_P (elt_type) != POINTER_TYPE_P (init_type)
|| !type_initializer_zero_p (elt_type, elt_init))
last_nonzero = index;
...and a test case involving an ordinary pointer is diagnosed:
$ cat t.C && gcc -S -Wall t.C
int a[2] = { nullptr };
int b[2] = { (void*)0 };
t.C:2:23: error: invalid conversion from ‘void*’ to ‘int’ [-fpermissive]
2 | int b[2] = { (void*)0 };
| ^
| |
| void*
but a nullptr use is not.
(gdb) p debug_tree (init_type)
$6 = (tree) 0x7fffea9521f8
<nullptr_type 0x7fffea9521f8 decltype(nullptr) public unsigned DI
size <integer_cst 0x7fffea7f7e70 type <integer_type 0x7fffea8150a8
bitsizetype> constant 64>
unit-size <integer_cst 0x7fffea7f7e88 type <integer_type 0x7fffea815000
sizetype> constant 8>
align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7fffea9521f8>
I would expect POINTER_TYPE_P (init_type) to be non-zero but it's not:
(gdb) p POINTER_TYPE_P (init_type)
$7 = false
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/94510] [9/10 Regression] nullptr_t implicitly cast to zero twice in std::array
2020-04-07 8:23 [Bug c++/94510] New: nullptr_t implicitly cast to zero twice in std::array kndevl at outlook dot com
` (8 preceding siblings ...)
2020-04-07 16:08 ` msebor at gcc dot gnu.org
@ 2020-04-07 18:51 ` msebor at gcc dot gnu.org
2020-04-22 6:28 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-04-07 18:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94510
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
--- Comment #10 from Martin Sebor <msebor at gcc dot gnu.org> ---
POINTER_TYPE_P() is zero because while nullptr is specified to be "the pointer
literal is the keyword nullptr" it also "...is a prvalue of type
std::nullptr_t. [Note: std::nullptr_t is a distinct type that is neither a
pointer type nor a pointer-to-member type; ..." Of course -- a pointer literal
that doesn't have a pointer type, makes perfect sense.
Another closely related regression r270155 introduced is the missing warning
for the following test case:
$ cat t.C && gcc-8 -S -Wall t.C
#include <stddef.h>
int a[2] = { NULL };
t.C:3:19: warning: converting to non-pointer type ‘int’ from NULL
[-Wconversion-null]
int a[2] = { NULL };
^
The patch at the link below restores both diagnostics:
https://gcc.gnu.org/pipermail/gcc-patches/2020-April/543482.html
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/94510] [9/10 Regression] nullptr_t implicitly cast to zero twice in std::array
2020-04-07 8:23 [Bug c++/94510] New: nullptr_t implicitly cast to zero twice in std::array kndevl at outlook dot com
` (9 preceding siblings ...)
2020-04-07 18:51 ` msebor at gcc dot gnu.org
@ 2020-04-22 6:28 ` cvs-commit at gcc dot gnu.org
2020-04-22 6:29 ` [Bug c++/94510] [9 " jason at gcc dot gnu.org
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-04-22 6:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94510
--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:
https://gcc.gnu.org/g:587970215f4681def390e2a791aa3ba6adb65158
commit r10-7864-g587970215f4681def390e2a791aa3ba6adb65158
Author: Martin Sebor <msebor@gmail.com>
Date: Wed Apr 22 02:27:54 2020 -0400
c++: reject scalar array initialization with nullptr [PR94510]
The change committed to GCC 9 to allow string literals as template
arguments
caused the compiler to prune away, and thus miss diagnosing, conversion
from
nullptr to int in an array initializer. After looking at various
approaches
to improving the pruning, we realized that the only place the pruning is
necessary is in the mangler.
gcc/cp/ChangeLog
2020-04-22 Martin Sebor <msebor@redhat.com>
Jason Merrill <jason@redhat.com>
PR c++/94510
* decl.c (reshape_init_array_1): Avoid stripping redundant trailing
zero initializers...
* mangle.c (write_expression): ...and handle them here even for
pointers to members by calling zero_init_expr_p.
* cp-tree.h (zero_init_expr_p): Declare.
* tree.c (zero_init_expr_p): Define.
(type_initializer_zero_p): Remove.
* pt.c (tparm_obj_values): New hash_map.
(get_template_parm_object): Store to it.
(tparm_object_argument): New.
gcc/testsuite/ChangeLog
2020-04-22 Martin Sebor <msebor@redhat.com>
PR c++/94510
* g++.dg/init/array58.C: New test.
* g++.dg/init/array59.C: New test.
* g++.dg/cpp2a/nontype-class34.C: New test.
* g++.dg/cpp2a/nontype-class35.C: New test.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/94510] [9 Regression] nullptr_t implicitly cast to zero twice in std::array
2020-04-07 8:23 [Bug c++/94510] New: nullptr_t implicitly cast to zero twice in std::array kndevl at outlook dot com
` (10 preceding siblings ...)
2020-04-22 6:28 ` cvs-commit at gcc dot gnu.org
@ 2020-04-22 6:29 ` jason at gcc dot gnu.org
2020-04-22 20:39 ` cvs-commit at gcc dot gnu.org
2020-04-22 21:56 ` jason at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2020-04-22 6:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94510
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
Summary|[9/10 Regression] nullptr_t |[9 Regression] nullptr_t
|implicitly cast to zero |implicitly cast to zero
|twice in std::array |twice in std::array
--- Comment #12 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 10 so far.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/94510] [9 Regression] nullptr_t implicitly cast to zero twice in std::array
2020-04-07 8:23 [Bug c++/94510] New: nullptr_t implicitly cast to zero twice in std::array kndevl at outlook dot com
` (11 preceding siblings ...)
2020-04-22 6:29 ` [Bug c++/94510] [9 " jason at gcc dot gnu.org
@ 2020-04-22 20:39 ` cvs-commit at gcc dot gnu.org
2020-04-22 21:56 ` jason at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-04-22 20:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94510
--- Comment #13 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:
https://gcc.gnu.org/g:35699e75a502bb25a2cb23a456e8d6f036b8f226
commit r9-8526-g35699e75a502bb25a2cb23a456e8d6f036b8f226
Author: Martin Sebor <msebor@gmail.com>
Date: Tue Apr 21 11:02:06 2020 -0400
c++: reject scalar array initialization with nullptr [PR94510]
The change committed to GCC 9 to allow string literals as template
arguments
caused the compiler to prune away, and thus miss diagnosing, conversion
from
nullptr to int in an array initializer. After looking at various
approaches
to improving the pruning, we realized that the only place the pruning is
necessary is in the mangler.
gcc/cp/ChangeLog
2020-04-21 Martin Sebor <msebor@redhat.com>
Jason Merrill <jason@redhat.com>
PR c++/94510
* decl.c (reshape_init_array_1): Avoid stripping redundant trailing
zero initializers...
* mangle.c (write_expression): ...and handle them here even for
pointers to members by calling zero_init_expr_p.
* cp-tree.h (zero_init_expr_p): Declare.
* tree.c (zero_init_expr_p): Define.
(type_initializer_zero_p): Remove.
* pt.c (tparm_obj_values): New hash_map.
(get_template_parm_object): Store to it.
(tparm_object_argument): New.
gcc/testsuite/ChangeLog
2020-04-21 Martin Sebor <msebor@redhat.com>
PR c++/94510
* g++.dg/init/array58.C: New test.
* g++.dg/init/array59.C: New test.
* g++.dg/cpp2a/nontype-class34.C: New test.
* g++.dg/cpp2a/nontype-class35.C: New test.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/94510] [9 Regression] nullptr_t implicitly cast to zero twice in std::array
2020-04-07 8:23 [Bug c++/94510] New: nullptr_t implicitly cast to zero twice in std::array kndevl at outlook dot com
` (12 preceding siblings ...)
2020-04-22 20:39 ` cvs-commit at gcc dot gnu.org
@ 2020-04-22 21:56 ` jason at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2020-04-22 21:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94510
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #14 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 9.4/10.
^ permalink raw reply [flat|nested] 15+ messages in thread