]> granicus.if.org Git - clang/commitdiff
References to const int parameters with ICE default arguments are not ICEs.
authorJohn McCall <rjmccall@apple.com>
Wed, 24 Feb 2010 09:03:18 +0000 (09:03 +0000)
committerJohn McCall <rjmccall@apple.com>
Wed, 24 Feb 2010 09:03:18 +0000 (09:03 +0000)
Fixes PR6373.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97037 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
test/SemaCXX/i-c-e-cxx.cpp

index fac65064c07c586092a3716e17082a90c8e571c8..a2914bc6bf4e1bacd34a6c3984c418268f5092f6 100644 (file)
@@ -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());
index 4f2f1974678347af520142caaf83e4b1711b1359..e8275d463de5763f6a792577f652ef0f8304b5c4 100644 (file)
@@ -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;
+}