diff options
author | John McCall <rjmccall@apple.com> | 2010-02-24 09:03:18 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-02-24 09:03:18 +0000 |
commit | f604a5648d201d2350e1631a755121e9b837f9f2 (patch) | |
tree | c5b4aa90950db5d497c091f9520218c15d567ac4 /lib/AST/Expr.cpp | |
parent | 1a4bb5cc1b545d7e359d20e30c0df54efd4b1b02 (diff) |
References to const int parameters with ICE default arguments are not ICEs.
Fixes PR6373.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97037 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Expr.cpp')
-rw-r--r-- | lib/AST/Expr.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index fac65064c0..a2914bc6bf 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1682,11 +1682,18 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) { return NoDiag(); if (Ctx.getLangOptions().CPlusPlus && E->getType().getCVRQualifiers() == Qualifiers::Const) { + const NamedDecl *D = cast<DeclRefExpr>(E)->getDecl(); + + // Parameter variables are never constants. Without this check, + // getAnyInitializer() can find a default argument, which leads + // to chaos. + if (isa<ParmVarDecl>(D)) + return ICEDiag(2, cast<DeclRefExpr>(E)->getLocation()); + // 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>(E)->getDecl())) { + if (const VarDecl *Dcl = dyn_cast<VarDecl>(D)) { Qualifiers Quals = Ctx.getCanonicalType(Dcl->getType()).getQualifiers(); if (Quals.hasVolatile() || !Quals.hasConst()) return ICEDiag(2, cast<DeclRefExpr>(E)->getLocation()); |