From: John McCall Date: Wed, 24 Feb 2010 09:03:18 +0000 (+0000) Subject: References to const int parameters with ICE default arguments are not ICEs. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f604a5648d201d2350e1631a755121e9b837f9f2;p=clang 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 --- 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(E)->getDecl(); + + // Parameter variables are never constants. Without this check, + // getAnyInitializer() can find a default argument, which leads + // to chaos. + if (isa(D)) + return ICEDiag(2, cast(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(cast(E)->getDecl())) { + if (const VarDecl *Dcl = dyn_cast(D)) { Qualifiers Quals = Ctx.getCanonicalType(Dcl->getType()).getQualifiers(); if (Quals.hasVolatile() || !Quals.hasConst()) return ICEDiag(2, cast(E)->getLocation()); diff --git a/test/SemaCXX/i-c-e-cxx.cpp b/test/SemaCXX/i-c-e-cxx.cpp index 4f2f197467..e8275d463d 100644 --- a/test/SemaCXX/i-c-e-cxx.cpp +++ b/test/SemaCXX/i-c-e-cxx.cpp @@ -37,3 +37,8 @@ namespace pr6206 { return str[0]; } } + +// PR6373: default arguments don't count. +void pr6373(const unsigned x = 0) { + unsigned max = 80 / x; +}