diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 4316596bb32a5..e9a58289f6fc0 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2749,10 +2749,9 @@ bool ByteCodeExprGen::visitVarDecl(const VarDecl *VD) { return this->emitSetLocal(*VarT, Offset, VD); } } else { - if (std::optional Offset = this->allocateLocal(VD)) { - if (Init) - return this->visitLocalInitializer(Init, *Offset); - } + if (std::optional Offset = this->allocateLocal(VD)) + return !Init || this->visitLocalInitializer(Init, *Offset); + return false; } return true; } diff --git a/clang/test/AST/Interp/arrays.cpp b/clang/test/AST/Interp/arrays.cpp index a9450d827f6be..e1af2e80e3ad7 100644 --- a/clang/test/AST/Interp/arrays.cpp +++ b/clang/test/AST/Interp/arrays.cpp @@ -545,3 +545,22 @@ namespace LocalIndex { array[const_subscript] = 0; // both-warning {{array index 3 is past the end of the array (that has type 'int[2]')}} } } + +namespace LocalVLA { + struct Foo { + int x; + Foo(int x) : x(x) {} + }; + struct Elidable { + Elidable(); + }; + + void foo(int size) { + Elidable elidableDynArray[size]; +#if __cplusplus >= 202002L + // both-note@-3 {{declared here}} + // both-warning@-3 {{variable length array}} + // both-note@-4 {{function parameter 'size' with unknown value}} +#endif + } +}