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 | 6dee4737803a02455c4c7c8362b7cdf439c68eff (patch) | |
| tree | 70d3cd319c8ef7380a38f8961e44692b3a095b7b | |
| parent | 693ea8921479261b313e49f232d7110da66da126 (diff) | |
| download | bcm5719-llvm-6dee4737803a02455c4c7c8362b7cdf439c68eff.tar.gz bcm5719-llvm-6dee4737803a02455c4c7c8362b7cdf439c68eff.zip | |
References to const int parameters with ICE default arguments are not ICEs.
Fixes PR6373.
llvm-svn: 97037
| -rw-r--r-- | clang/lib/AST/Expr.cpp | 11 | ||||
| -rw-r--r-- | clang/test/SemaCXX/i-c-e-cxx.cpp | 5 |
2 files changed, 14 insertions, 2 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index fac65064c07..a2914bc6bf4 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/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()); diff --git a/clang/test/SemaCXX/i-c-e-cxx.cpp b/clang/test/SemaCXX/i-c-e-cxx.cpp index 4f2f1974678..e8275d463de 100644 --- a/clang/test/SemaCXX/i-c-e-cxx.cpp +++ b/clang/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; +} |

