sizeof a VLA type is not a constant in C or the GNU C++ extension, so we
need to capture the VLA even in unevaluated context. For PR60855 we stopped
looking through a previous capture, but we also need to capture the first
time the variable is mentioned.
PR c++/86216
* semantics.c (process_outer_var_ref): Capture VLAs even in
unevaluated context.
2020-01-31 Jason Merrill <jason@redhat.com>
+ PR c++/86216
+ * semantics.c (process_outer_var_ref): Capture VLAs even in
+ unevaluated context.
+
PR c++/14179
* decl.c (reshape_init_array_1): Reuse a single CONSTRUCTOR with
non-aggregate elements.
process_outer_var_ref (tree decl, tsubst_flags_t complain, bool odr_use)
{
if (cp_unevaluated_operand)
- /* It's not a use (3.2) if we're in an unevaluated context. */
- return decl;
+ {
+ tree type = TREE_TYPE (decl);
+ if (!dependent_type_p (type)
+ && variably_modified_type_p (type, NULL_TREE))
+ /* VLAs are used even in unevaluated context. */;
+ else
+ /* It's not a use (3.2) if we're in an unevaluated context. */
+ return decl;
+ }
if (decl == error_mark_node)
return decl;
--- /dev/null
+// PR c++/86216
+// { dg-do compile { target c++11 } }
+// { dg-additional-options -Wno-vla }
+
+template <typename T> void b(int n, T arg) {
+ int buffer[arg];
+ int buffer2[arg][arg];
+ [&] {
+ n = sizeof(buffer);
+ n = sizeof(buffer2); // { dg-bogus "sorry" "" { xfail *-*-* } }
+ }();
+}
+int main() { b(2, 3); }