Address constants (C99 6.6p9) are not handled. (r43994)
The standard says that the rules for constant expressions in
initializers are more lax than for other constant expressions. Does
this mean isConstantInitializer is needed in addition to
isConstantExpr, like isIntegerConstantExpr?
It seems that current isConstantExpr is used as isConstantInitializer,
so I patched isConstantExpr directly.
A rather incomplete implementation and a test is attached.
--
Seo Sanghyeon
Index: AST/Expr.cpp
===================================================================
--- AST/Expr.cpp (revision 43994)
+++ AST/Expr.cpp (working copy)
@@ -394,6 +394,13 @@
case UnaryOperatorClass: {
const UnaryOperator *Exp = cast<UnaryOperator>(this);
+ // C99 6.6p9
+ if (Exp->getOpcode() == UnaryOperator::AddrOf)
+ if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Exp->getSubExpr()))
+ if (VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl()))
+ if (VD->hasStaticStorage())
+ return true;
+
// Get the operand value. If this is sizeof/alignof, do not evalute the
// operand. This affects C99 6.6p3.
if (!Exp->isSizeOfAlignOfOp() &&
Index: test/Sema/address-constant.c
===================================================================
--- test/Sema/address-constant.c (revision 0)
+++ test/Sema/address-constant.c (revision 0)
@@ -0,0 +1,4 @@
+// RUN: clang -fsyntax-only -verify %s
+
+int a;
+int *b[] = {&a};
_______________________________________________
cfe-dev mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev