diff options
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 7e60da5af3..564f530191 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1163,6 +1163,13 @@ bool Sema::CheckArithmeticConstantExpression(const Expr* Init) { if (SubExpr->getType()->isArithmeticType()) return CheckArithmeticConstantExpression(SubExpr); + if (SubExpr->getType()->isPointerType()) { + const Expr* Base = FindExpressionBaseAddress(SubExpr); + // If the pointer has a null base, this is an offsetof-like construct + if (!Base) + return CheckAddressConstantExpression(SubExpr); + } + Diag(Init->getExprLoc(), diag::err_init_element_not_constant, Init->getSourceRange()); return true; |