c++: reject scalar array initialization with nullptr [PR94510]
authorMartin Sebor <msebor@gmail.com>
Wed, 22 Apr 2020 06:27:54 +0000 (02:27 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 22 Apr 2020 06:27:54 +0000 (02:27 -0400)
commit587970215f4681def390e2a791aa3ba6adb65158
tree7fa9b0fe0ce7efd2a32648ee5a9accf301858ea5
parent0fe9eaaa083b6cc032cbd3ad1286b1dd73ccdf54
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.
12 files changed:
gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/mangle.c
gcc/cp/pt.c
gcc/cp/tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/abi/mangle72.C
gcc/testsuite/g++.dg/cpp2a/nontype-class36.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/nontype-class37.C [new file with mode: 0644]
gcc/testsuite/g++.dg/init/array58.C [new file with mode: 0644]
gcc/testsuite/g++.dg/init/array59.C [new file with mode: 0644]