[PATCH] D32372: Arrays of unknown bound in constant expressions
Richard Smith via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 28 17:52:25 PDT 2017
rsmith added a comment.
Thanks, this looks good, just a couple of minor things and then it should be ready to land.
Do you have commit access or will you need someone else to commit this for you?
================
Comment at: lib/AST/ExprConstant.cpp:152
+ uint64_t &ArraySize, QualType &Type, bool &IsArray,
+ bool &isUnsizedArray) {
// This only accepts LValueBases from APValues, and APValues don't support
----------------
Please start variable names with an uppercase letter.
================
Comment at: lib/AST/ExprConstant.cpp:168
+ ArraySize = 0;
+ isUnsizedArray = true;
+ }
----------------
The other 'most derived' paths through here should set this back to `false` (a sized array in a field in an element of an unsized array does not give an unsized array).
================
Comment at: lib/AST/ExprConstant.cpp:1301
void addUnsizedArray(EvalInfo &Info, QualType ElemTy) {
- assert(Designator.Entries.empty() && getType(Base)->isPointerType());
- assert(isBaseAnAllocSizeCall(Base) &&
- "Only alloc_size bases can have unsized arrays");
- Designator.FirstEntryIsAnUnsizedArray = true;
Designator.addUnsizedArrayUnchecked(ElemTy);
}
----------------
We should call `checkSubobject` here, for cases like:
```
void f(int n) {
int arr[2][n];
constexpr int *p = &arr[2][0];
}
```
... which we should reject because `arr[2]` is a one-past-the-end lvalue, so cannot be indexed (we reject this if `n` is instead a constant).
https://reviews.llvm.org/D32372
More information about the cfe-commits
mailing list