c++: Fix VLA in template [PR95232]
authorJason Merrill <jason@redhat.com>
Tue, 2 Jun 2020 20:23:02 +0000 (16:23 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 3 Jun 2020 18:06:17 +0000 (14:06 -0400)
commitef4e0c35546ba2c897613925c1d2485603ca3ab1
tree5d209b6ffdcdb2555a52c17ce15c951e398e332f
parent8d57c30611b05a89fd265f6c0a74fe829c21cd34
c++: Fix VLA in template [PR95232]

In a non-template, grokdeclarator notices when we build a pointer to a
variably-modified type, and inserts a TYPE_DECL to make sure that type gets
gimplified.  But in a template we can't always recognize a variably-modified
type, so we need to deal with it at instantiation time.

gcc/cp/ChangeLog:

PR c++/95232
* cp-tree.h (predeclare_vla): Declare.
* cp-gimplify.c (predeclare_vla): Handle getting a decl.
* pt.c (tsubst_expr) [DECL_EXPR]: Use it.

gcc/testsuite/ChangeLog:

PR c++/95232
* g++.dg/ubsan/vla-2.C: New test.
gcc/cp/cp-gimplify.c
gcc/cp/cp-tree.h
gcc/cp/pt.c
gcc/testsuite/g++.dg/ubsan/vla-2.C [new file with mode: 0644]