diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index d686167cd0b4..904fe5f99c34 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(cast(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 000000000000..64ffe8bce8d6 --- /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 a5a0454ab8a2..95ce0e5c15bb 100644 --- a/clang/www/cxx_status.html +++ b/clang/www/cxx_status.html @@ -1013,9 +1013,9 @@ welcome!

      7.1.5.1 [dcl.type.cv] ✓ ✓ - + ✓ + - Const integral variables with ICE initializers are not ICEs.       7.1.5.2 [dcl.type.simple]