зеркало из https://github.com/microsoft/clang-1.git
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
This commit is contained in:
Родитель
6f7adbdcd0
Коммит
b529d830b3
|
@ -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;
|
||||
|
|
|
@ -58,3 +58,11 @@ union { float f; unsigned u; } u = { 1.0f };
|
|||
int f3(int x) { return x; }
|
||||
typedef void (*vfunc)(void);
|
||||
void *bar = (vfunc) f3;
|
||||
|
||||
// PR2747
|
||||
struct sym_reg {
|
||||
char nc_gpreg;
|
||||
};
|
||||
int sym_fw1a_scr[] = {
|
||||
((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче