================
@@ -11791,6 +11791,26 @@ QualType Sema::CheckAdditionOperands(ExprResult &LHS, 
ExprResult &RHS,
   return PExp->getType();
 }
 
+/// Determine whether the size of \p T is provably zero: some array dimension
+/// is provably zero or the base element type has zero size. A variable
+/// dimension that does not fold to an integer constant is assumed nonzero.
+static bool isProvablyZeroSize(const ASTContext &Ctx, QualType T) {
+  while (const ArrayType *AT = Ctx.getAsArrayType(T)) {
+    if (const auto *CAT = dyn_cast<ConstantArrayType>(AT)) {
+      if (CAT->isZeroSize())
+        return true;
+    } else if (const auto *VAT = dyn_cast<VariableArrayType>(AT)) {
+      if (const Expr *Bound = VAT->getSizeExpr())
----------------
AaronBallman wrote:

Can you add some C++ tests where the size expression is a dependent value, just 
to be sure the behavior there is reasonable with and without instantiation? 
e.g.,
```
template <int N>
int not_instantiated() {
  int array[N];
  return &array - &array; // no diagnostic
}

template <int N>
int instantiated() {
  int array[N];
  return &array - &array; // diagnostic
}

int x = instantiated<0>; // template instantiation note
int y = instantiated<1>; // okay
```

https://github.com/llvm/llvm-project/pull/217465
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to