[cfe-commits] r97037 - in /cfe/trunk: lib/AST/Expr.cpp test/SemaCXX/i-c-e-cxx.cpp

John McCall rjmccall at apple.com
Wed Feb 24 01:03:18 PST 2010


Author: rjmccall
Date: Wed Feb 24 03:03:18 2010
New Revision: 97037

URL: http://llvm.org/viewvc/llvm-project?rev=97037&view=rev
Log:
References to const int parameters with ICE default arguments are not ICEs.
Fixes PR6373.


Modified:
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=97037&r1=97036&r2=97037&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Wed Feb 24 03:03:18 2010
@@ -1682,11 +1682,18 @@
       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());

Modified: cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp?rev=97037&r1=97036&r2=97037&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp (original)
+++ cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp Wed Feb 24 03:03:18 2010
@@ -37,3 +37,8 @@
     return str[0];
   }
 }
+
+// PR6373:  default arguments don't count.
+void pr6373(const unsigned x = 0) {
+  unsigned max = 80 / x;
+}





More information about the cfe-commits mailing list