diff options
-rw-r--r-- | clang/lib/AST/ByteCode/Compiler.cpp | 20 | ||||
-rw-r--r-- | clang/test/AST/ByteCode/cxx23.cpp | 12 |
2 files changed, 23 insertions, 9 deletions
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index db87ea1..e4f87d8 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -6823,15 +6823,17 @@ bool Compiler<Emitter>::emitDestruction(const Descriptor *Desc, return true; } - for (ssize_t I = Desc->getNumElems() - 1; I >= 0; --I) { - if (!this->emitConstUint64(I, Loc)) - return false; - if (!this->emitArrayElemPtrUint64(Loc)) - return false; - if (!this->emitDestruction(ElemDesc, Loc)) - return false; - if (!this->emitPopPtr(Loc)) - return false; + if (size_t N = Desc->getNumElems()) { + for (ssize_t I = N - 1; I >= 0; --I) { + if (!this->emitConstUint64(I, Loc)) + return false; + if (!this->emitArrayElemPtrUint64(Loc)) + return false; + if (!this->emitDestruction(ElemDesc, Loc)) + return false; + if (!this->emitPopPtr(Loc)) + return false; + } } return true; } diff --git a/clang/test/AST/ByteCode/cxx23.cpp b/clang/test/AST/ByteCode/cxx23.cpp index 6a62ac1..d0ade4f 100644 --- a/clang/test/AST/ByteCode/cxx23.cpp +++ b/clang/test/AST/ByteCode/cxx23.cpp @@ -304,3 +304,15 @@ namespace NonLiteralDtorInParam { // expected23-note {{non-constexpr function '~NonLiteral' cannot be used in a constant expression}} } } + +namespace ZeroSizedArray { + struct S { + constexpr ~S() { + } + }; + constexpr int foo() { + S s[0]; + return 1; + } + static_assert(foo() == 1); +} |