diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index 6cf122f2ba55e1..a240d74d63425e 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -1826,10 +1826,12 @@ inline bool ArrayElemPtr(InterpState &S, CodePtr OpPC) { /// Just takes a pointer and checks if its' an incomplete /// array type. inline bool ArrayDecay(InterpState &S, CodePtr OpPC) { - const Pointer &Ptr = S.Stk.peek(); + const Pointer &Ptr = S.Stk.pop(); - if (!Ptr.isUnknownSizeArray()) + if (!Ptr.isUnknownSizeArray()) { + S.Stk.push(Ptr.atIndex(0)); return true; + } const SourceInfo &E = S.Current->getSource(OpPC); S.FFDiag(E, diag::note_constexpr_unsupported_unsized_array); diff --git a/clang/test/AST/Interp/arrays.cpp b/clang/test/AST/Interp/arrays.cpp index 34e0086fb9ee8c..c455731e76699f 100644 --- a/clang/test/AST/Interp/arrays.cpp +++ b/clang/test/AST/Interp/arrays.cpp @@ -27,6 +27,10 @@ static_assert(foo[2][3] == &m, ""); static_assert(foo[2][4] == nullptr, ""); +constexpr int SomeInt[] = {1}; +constexpr int getSomeInt() { return *SomeInt; } +static_assert(getSomeInt() == 1, ""); + /// A init list for a primitive value. constexpr int f{5}; static_assert(f == 5, "");