From c9ab3d430bb400dc1f90b69cae725fbc4508f9d3 Mon Sep 17 00:00:00 2001 From: Sebastian Redl Date: Sun, 8 Feb 2009 15:51:17 +0000 Subject: Teach the constant evaluator about C++ const integral variables. llvm-svn: 64086 --- clang/lib/AST/ExprConstant.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'clang/lib/AST/ExprConstant.cpp') 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(E->getDecl())) { + if (const Expr *Init = D->getInit()) + return Visit(const_cast(Init)); + } + } + // Otherwise, random variable references are not constants. return Error(E->getLocStart(), diag::note_invalid_subexpr_in_ice, E); } -- cgit v1.2.3