c++: Fix crash with broken deduction from {} [PR97895]
commit25056bdf94d5f3e66bef039702f7fae799ef16b9
authorMarek Polacek <polacek@redhat.com>
Thu, 19 Nov 2020 03:49:59 +0000 (18 22:49 -0500)
committerMarek Polacek <polacek@redhat.com>
Thu, 19 Nov 2020 18:14:41 +0000 (19 13:14 -0500)
tree75c4f85b1eb7fda62c5fbf90379a9b1e7eadccbb
parente1f07131e2d88b08f75ffea2a8dcfb16607629aa
c++: Fix crash with broken deduction from {} [PR97895]

Unfortunately, the otherwise beautiful

  for (constructor_elt &elt : *CONSTRUCTOR_ELTS (init))

is not immune to an empty constructor, so we have to check
CONSTRUCTOR_ELTS first.

gcc/cp/ChangeLog:

PR c++/97895
* pt.c (do_auto_deduction): Don't crash when the constructor has
zero elements.

gcc/testsuite/ChangeLog:

PR c++/97895
* g++.dg/cpp0x/auto54.C: New test.
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp0x/auto54.C [new file with mode: 0644]