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 | c9ab3d430bb400dc1f90b69cae725fbc4508f9d3 (patch) | |
| tree | e890461c7165d9e8e4c2cdb471a90fa47dd5426a | |
| parent | df0913ba70529f10f56714e53162f422a4bab4c3 (diff) | |
| download | bcm5719-llvm-c9ab3d430bb400dc1f90b69cae725fbc4508f9d3.tar.gz bcm5719-llvm-c9ab3d430bb400dc1f90b69cae725fbc4508f9d3.zip | |
Teach the constant evaluator about C++ const integral variables.
llvm-svn: 64086
| -rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 97985205077..c7cc85425c8 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/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); } |

