diff --git a/clang/lib/AST/Interp/Pointer.cpp b/clang/lib/AST/Interp/Pointer.cpp index b2e3a7ff70881e..ff4da0fa805dcf 100644 --- a/clang/lib/AST/Interp/Pointer.cpp +++ b/clang/lib/AST/Interp/Pointer.cpp @@ -152,8 +152,9 @@ APValue Pointer::toAPValue() const { Pointer Ptr = *this; while (Ptr.isField() || Ptr.isArrayElement()) { if (Ptr.isArrayRoot()) { - Path.push_back(APValue::LValuePathEntry::ArrayIndex(0)); - Ptr = Ptr.getBase(); + Path.push_back(APValue::LValuePathEntry( + {Ptr.getFieldDesc()->asDecl(), /*IsVirtual=*/false})); + Ptr = Ptr.getBase(); } else if (Ptr.isArrayElement()) { if (Ptr.isOnePastEnd()) Path.push_back(APValue::LValuePathEntry::ArrayIndex(Ptr.getArray().getNumElems())); diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index fa29e08a301757..f190262ad3ebee 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -644,3 +644,21 @@ namespace FunctionCast { // both-warning {{are a Clang extension}} int b[(int)IntFn(f)()]; // ok } + +#if __cplusplus >= 202002L +namespace StableAddress { + template struct str { + char arr[N]; + }; + // FIXME: Deduction guide not needed with P1816R0. + template str(const char (&)[N]) -> str; + + template constexpr int sum() { + int n = 0; + for (char c : s.arr) + n += c; + return n; + } + static_assert(sum() == 1234, ""); +} +#endif