]> granicus.if.org Git - clang/commitdiff
Make const-initialized const integral variables I-C-Es in C++.
authorSebastian Redl <sebastian.redl@getdesigned.at>
Sat, 7 Feb 2009 13:06:23 +0000 (13:06 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Sat, 7 Feb 2009 13:06:23 +0000 (13:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64015 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
test/SemaCXX/i-c-e-cxx.cpp [new file with mode: 0644]
www/cxx_status.html

index d686167cd0b49cc9dedb11f4b08c5d9b52ba0b7b..904fe5f99c345176297bd7edfae409b1d3a7d7cb 100644 (file)
@@ -865,6 +865,17 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
       Result = D->getInitVal();
       break;
     }
+    if (Ctx.getLangOptions().CPlusPlus &&
+        getType().getCVRQualifiers() == QualType::Const) {
+      // C++ 7.1.5.1p2
+      //   A variable of non-volatile const-qualified integral or enumeration
+      //   type initialized by an ICE can be used in ICEs.
+      if (const VarDecl *Dcl =
+              dyn_cast<VarDecl>(cast<DeclRefExpr>(this)->getDecl())) {
+        if (const Expr *Init = Dcl->getInit())
+          return Init->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated);
+      }
+    }
     if (Loc) *Loc = getLocStart();
     return false;
   case UnaryOperatorClass: {
diff --git a/test/SemaCXX/i-c-e-cxx.cpp b/test/SemaCXX/i-c-e-cxx.cpp
new file mode 100644 (file)
index 0000000..64ffe8b
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: clang -fsyntax-only -verify %s
+
+// C++-specific tests for integral constant expressions.
+
+const int c = 10;
+int ar[c];
index a5a0454ab8a2fbdb8c62b17d3f5f2c6dfd854d88..95ce0e5c15bb4961f54ebb0d75a24e13498d7e1f 100644 (file)
@@ -1013,9 +1013,9 @@ welcome!</p>
   <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7.1.5.1 [dcl.type.cv]</td>\r
   <td class="complete" align="center">&#x2713;</td>\r
   <td class="complete" align="center">&#x2713;</td>\r
-  <td class="medium"></td>\r
+  <td class="complete" align="center">&#x2713;</td>\r
+  <td></td>\r
   <td></td>\r
-  <td>Const integral variables with ICE initializers are not ICEs.</td>\r
 </tr>\r
 <tr>\r
   <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7.1.5.2 [dcl.type.simple]</td>\r