aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2008-09-02 09:37:00 +0000
committerEli Friedman <eli.friedman@gmail.com>2008-09-02 09:37:00 +0000
commitb529d830b3b1667157da92ab0b5c32e1acfafbab (patch)
tree155c1e48a5b3a5975d0ab41fdb72c123a19744b6 /lib/Sema/SemaDecl.cpp
parent6f7adbdcd07a6c13cb81bf3048d1e52f149a9377 (diff)
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
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r--lib/Sema/SemaDecl.cpp7
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;