diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2009-02-07 13:06:23 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2009-02-07 13:06:23 +0000 |
commit | f3b5e27feec3161ef1a0d73bec83dd74d3ccc86f (patch) | |
tree | c7074ff7853c57d13232abeb6a1b33e5fef67491 | |
parent | 1d91dd98ad68f98c5d0b79c41d3a9ffc590e35b7 (diff) | |
download | bcm5719-llvm-f3b5e27feec3161ef1a0d73bec83dd74d3ccc86f.tar.gz bcm5719-llvm-f3b5e27feec3161ef1a0d73bec83dd74d3ccc86f.zip |
Make const-initialized const integral variables I-C-Es in C++.
llvm-svn: 64015
-rw-r--r-- | clang/lib/AST/Expr.cpp | 11 | ||||
-rw-r--r-- | clang/test/SemaCXX/i-c-e-cxx.cpp | 6 | ||||
-rw-r--r-- | clang/www/cxx_status.html | 4 |
3 files changed, 19 insertions, 2 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index d686167cd0b..904fe5f99c3 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -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/clang/test/SemaCXX/i-c-e-cxx.cpp b/clang/test/SemaCXX/i-c-e-cxx.cpp new file mode 100644 index 00000000000..64ffe8bce8d --- /dev/null +++ b/clang/test/SemaCXX/i-c-e-cxx.cpp @@ -0,0 +1,6 @@ +// RUN: clang -fsyntax-only -verify %s + +// C++-specific tests for integral constant expressions. + +const int c = 10; +int ar[c]; diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html index a5a0454ab8a..95ce0e5c15b 100644 --- a/clang/www/cxx_status.html +++ b/clang/www/cxx_status.html @@ -1013,9 +1013,9 @@ welcome!</p> <td> 7.1.5.1 [dcl.type.cv]</td>
<td class="complete" align="center">✓</td>
<td class="complete" align="center">✓</td>
- <td class="medium"></td>
+ <td class="complete" align="center">✓</td>
+ <td></td>
<td></td>
- <td>Const integral variables with ICE initializers are not ICEs.</td>
</tr>
<tr>
<td> 7.1.5.2 [dcl.type.simple]</td>
|