Fix the location we emit the "not a constant" error for this:
int foo() {
typedef int x[foo()];
static int y = sizeof(x);
}
previously we'd emit it on the typedef, which made not sense at all.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45154 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/Expr.cpp b/AST/Expr.cpp
index f4f8900..e814d58 100644
--- a/AST/Expr.cpp
+++ b/AST/Expr.cpp
@@ -468,8 +468,10 @@
case UnaryOperator::SizeOf:
case UnaryOperator::AlignOf:
// sizeof(vla) is not a constantexpr: C99 6.5.3.4p2.
- if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx, Loc))
+ if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx)) {
+ if (Loc) *Loc = Exp->getOperatorLoc();
return false;
+ }
return true;
case UnaryOperator::LNot:
case UnaryOperator::Plus:
@@ -481,8 +483,10 @@
case SizeOfAlignOfTypeExprClass: {
const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this);
// alignof always evaluates to a constant.
- if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx,Loc))
+ if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx)) {
+ if (Loc) *Loc = Exp->getOperatorLoc();
return false;
+ }
return true;
}
case BinaryOperatorClass: {
@@ -612,8 +616,10 @@
case UnaryOperator::SizeOf:
case UnaryOperator::AlignOf:
// sizeof(vla) is not a constantexpr: C99 6.5.3.4p2.
- if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx, Loc))
+ if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx)) {
+ if (Loc) *Loc = Exp->getOperatorLoc();
return false;
+ }
// Return the result in the right width.
Result.zextOrTrunc(
@@ -654,8 +660,10 @@
case SizeOfAlignOfTypeExprClass: {
const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this);
// alignof always evaluates to a constant.
- if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx,Loc))
+ if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx)) {
+ if (Loc) *Loc = Exp->getOperatorLoc();
return false;
+ }
// Return the result in the right width.
Result.zextOrTrunc(