Fix for PR2747: allow pointer->int casts with a null base; these are
offset-of-like expressions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55627 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 7e60da5..564f530 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1163,6 +1163,13 @@
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;