File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -223,6 +223,7 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
223223 UsePath = false ;
224224
225225 // Build the path into the object.
226+ bool OnePastEnd = isOnePastEnd ();
226227 Pointer Ptr = *this ;
227228 while (Ptr.isField () || Ptr.isArrayElement ()) {
228229
@@ -251,9 +252,10 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
251252 Ptr = Ptr.expand ();
252253 const Descriptor *Desc = Ptr.getFieldDesc ();
253254 unsigned Index;
254- if (Ptr.isOnePastEnd ())
255+ if (Ptr.isOnePastEnd ()) {
255256 Index = Ptr.getArray ().getNumElems ();
256- else
257+ OnePastEnd = false ;
258+ } else
257259 Index = Ptr.getIndex ();
258260
259261 QualType ElemType = Desc->getElemQualType ();
@@ -304,8 +306,7 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
304306 std::reverse (Path.begin (), Path.end ());
305307
306308 if (UsePath)
307- return APValue (Base, Offset, Path,
308- /* IsOnePastEnd=*/ !isElementPastEnd () && isOnePastEnd ());
309+ return APValue (Base, Offset, Path, OnePastEnd);
309310
310311 return APValue (Base, Offset, APValue::NoLValuePath ());
311312}
Original file line number Diff line number Diff line change @@ -761,3 +761,13 @@ namespace PointerSubscript {
761761 struct S {};
762762 static_assert ((foo<S>(), true ));
763763}
764+
765+ namespace OnePastEndDiag {
766+
767+ constexpr int a (const int *b) {
768+ return *b; // both-note {{read of dereferenced one-past-the-end pointer}}
769+ }
770+ constexpr int foo[] = {1 ,2 };
771+ constexpr int k = a(foo + 2 ); // both-error {{must be initialized by a constant expression}} \
772+ // both-note {{in call to 'a(&foo[2])'}}
773+ }
You can’t perform that action at this time.
0 commit comments