[PATCH] D32372: Arrays of unknown bound in constant expressions

Richard Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 1 12:03:07 PDT 2017


rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

Committed as r301822.



================
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);
     }
----------------
rsmith wrote:
> 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).
Turns out this case is already failing before we get here: forming `arr[2]` requires determining the size of the array element type `int[n]`, which fails.


https://reviews.llvm.org/D32372





More information about the cfe-commits mailing list