Please do not apply, it does not address all forms of variably modified types.
On Tue, Sep 22, 2026 at 11:24 PM Dylan Schooner <[email protected]> wrote: > Reflections of variable length arrays are invalid and should be > rejected. > > PR c++/127147 > > gcc/cp/ChangeLog: > > * reflect.cc (get_reflection): Reject VLAs. > > gcc/testsuite/ChangeLog: > > * g++.dg/reflect/pr127147.C: New test. > --- > gcc/cp/reflect.cc | 11 +++++++++++ > gcc/testsuite/g++.dg/reflect/pr127147.C | 9 +++++++++ > 2 files changed, 20 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/reflect/pr127147.C > > diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc > index 51f0885436e..cb9e901e5ae 100644 > --- a/gcc/cp/reflect.cc > +++ b/gcc/cp/reflect.cc > @@ -202,6 +202,17 @@ get_reflection (location_t loc, tree t, reflect_kind > kind/*=REFLECT_UNDEF*/) > error_at (loc, "%<^^%> cannot be applied to a concept check"); > return error_mark_node; > } > + /* A variable length array cannot appear as an operand of the > + reflection operator. */ > + else if (TREE_CODE (t) == ARRAY_TYPE) > + { > + tree nelts = array_type_nelts_top (t); > + if (!tree_fits_shwi_p (nelts)) > + { > + error_at (loc, "%<^^%> cannot be applied to a variable length > array"); > + return error_mark_node; > + } > + } > > /* Otherwise, if the template-name names a function template F, > then the template-name interpreted as an id-expression shall > diff --git a/gcc/testsuite/g++.dg/reflect/pr127147.C > b/gcc/testsuite/g++.dg/reflect/pr127147.C > new file mode 100644 > index 00000000000..af1fb7e7f8d > --- /dev/null > +++ b/gcc/testsuite/g++.dg/reflect/pr127147.C > @@ -0,0 +1,9 @@ > +// PR c++/127147 > +// { dg-do compile { target c++26 } } > +// { dg-additional-options "-freflection -Wno-vla" } > + > +consteval void > +foo (int a) > +{ > + auto b = ^^char[a]; // { dg-error "cannot be applied to a variable > length array" } > +} > -- > 2.55.0 > >
