]> granicus.if.org Git - clang/commitdiff
Teach the constant evaluator about C++ const integral variables.
authorSebastian Redl <sebastian.redl@getdesigned.at>
Sun, 8 Feb 2009 15:51:17 +0000 (15:51 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Sun, 8 Feb 2009 15:51:17 +0000 (15:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64086 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp

index 97985205077bbf848615c8f9e4b7904e10efa54d..c7cc85425c8d82fa51e04ae8a0de8d108d2afb1e 100644 (file)
@@ -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);
 }