diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2009-02-08 15:51:17 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2009-02-08 15:51:17 +0000 |
commit | b2bc62bd35129f09d0746ef6a5ef4dc392b6d6e1 (patch) | |
tree | 0867029f5d930311f80dace866810fbd01b52295 /lib/AST/ExprConstant.cpp | |
parent | 00d50747e8442a4d0daf2dfc226aec354fd3441e (diff) |
Teach the constant evaluator about C++ const integral variables.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64086 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r-- | lib/AST/ExprConstant.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 9798520507..c7cc85425c 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -574,7 +574,16 @@ bool IntExprEvaluator::VisitDeclRefExpr(const DeclRefExpr *E) { Result.setIsUnsigned(!E->getType()->isSignedIntegerType()); return true; } - + + // In C++, const, non-volatile integers initialized with ICEs are ICEs. + if (Info.Ctx.getLangOptions().CPlusPlus && + E->getType().getCVRQualifiers() == QualType::Const) { + if (const VarDecl *D = dyn_cast<VarDecl>(E->getDecl())) { + if (const Expr *Init = D->getInit()) + return Visit(const_cast<Expr*>(Init)); + } + } + // Otherwise, random variable references are not constants. return Error(E->getLocStart(), diag::note_invalid_subexpr_in_ice, E); } |