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
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 9798520..c7cc854 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -574,7 +574,16 @@
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);
}