File tree 2 files changed +15
-4
lines changed
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 {
223
223
UsePath = false ;
224
224
225
225
// Build the path into the object.
226
+ bool OnePastEnd = isOnePastEnd ();
226
227
Pointer Ptr = *this ;
227
228
while (Ptr .isField () || Ptr .isArrayElement ()) {
228
229
@@ -251,9 +252,10 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
251
252
Ptr = Ptr .expand ();
252
253
const Descriptor *Desc = Ptr .getFieldDesc ();
253
254
unsigned Index;
254
- if (Ptr .isOnePastEnd ())
255
+ if (Ptr .isOnePastEnd ()) {
255
256
Index = Ptr .getArray ().getNumElems ();
256
- else
257
+ OnePastEnd = false ;
258
+ } else
257
259
Index = Ptr .getIndex ();
258
260
259
261
QualType ElemType = Desc->getElemQualType ();
@@ -304,8 +306,7 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
304
306
std::reverse (Path.begin (), Path.end ());
305
307
306
308
if (UsePath)
307
- return APValue (Base, Offset, Path,
308
- /* IsOnePastEnd=*/ !isElementPastEnd () && isOnePastEnd ());
309
+ return APValue (Base, Offset, Path, OnePastEnd);
309
310
310
311
return APValue (Base, Offset, APValue::NoLValuePath ());
311
312
}
Original file line number Diff line number Diff line change @@ -761,3 +761,13 @@ namespace PointerSubscript {
761
761
struct S {};
762
762
static_assert ((foo<S>(), true ));
763
763
}
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