forked from OSchip/llvm-project
Make const-initialized const integral variables I-C-Es in C++.
llvm-svn: 64015
This commit is contained in:
parent
1d91dd98ad
commit
f3b5e27fee
|
@ -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: {
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
// RUN: clang -fsyntax-only -verify %s
|
||||
|
||||
// C++-specific tests for integral constant expressions.
|
||||
|
||||
const int c = 10;
|
||||
int ar[c];
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue