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

Robert Haberlach via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 21 14:01:23 PDT 2017


Arcoth created this revision.

Arrays of unknown bound are subject to some bugs in constant expressions.

const extern int arr[];
constexpr int f(int i) {return arr[i];}
constexpr int arr[] {1, 2, 3};
int main() {constexpr int x = f(2);}

This is spuriously rejected. On the other hand,

extern const int arr[];
constexpr int const* p = arr + 2;

compiles. The standard will presumably incorporate a rule that forbids array-to-pointer conversions on arrays of unknown bound (unless they are completed at the point of evaluation, as in the first
example). The proposed changes reflect this idea.


https://reviews.llvm.org/D32372

Files:
  include/clang/Basic/DiagnosticASTKinds.td
  lib/AST/ExprConstant.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32372.96225.patch
Type: text/x-patch
Size: 12306 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170421/822223c9/attachment-0001.bin>


More information about the cfe-commits mailing list