]> granicus.if.org Git - clang/commitdiff
When checking whether a reference to a variable is an ICE, look at the type of
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 24 Feb 2012 22:12:32 +0000 (22:12 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 24 Feb 2012 22:12:32 +0000 (22:12 +0000)
the declaration, not at the type of the DeclRefExpr, since within a lambda the
DeclRefExpr can be more const than the declaration is.

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

lib/AST/ExprConstant.cpp
test/SemaCXX/lambda-expressions.cpp

index b69a805f785aba91e4f17960285b6132e57e14de..44e41864f0b3a373fe3efb276a0a93c609fbe58d 100644 (file)
@@ -6379,12 +6379,12 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) {
       return CheckEvalInICE(E, Ctx);
     return ICEDiag(2, E->getLocStart());
   }
-  case Expr::DeclRefExprClass:
+  case Expr::DeclRefExprClass: {
     if (isa<EnumConstantDecl>(cast<DeclRefExpr>(E)->getDecl()))
       return NoDiag();
-    if (Ctx.getLangOptions().CPlusPlus && IsConstNonVolatile(E->getType())) {
-      const NamedDecl *D = cast<DeclRefExpr>(E)->getDecl();
-
+    const ValueDecl *D = dyn_cast<ValueDecl>(cast<DeclRefExpr>(E)->getDecl());
+    if (Ctx.getLangOptions().CPlusPlus &&
+        D && IsConstNonVolatile(D->getType())) {
       // Parameter variables are never constants.  Without this check,
       // getAnyInitializer() can find a default argument, which leads
       // to chaos.
@@ -6408,6 +6408,7 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) {
       }
     }
     return ICEDiag(2, E->getLocStart());
+  }
   case Expr::UnaryOperatorClass: {
     const UnaryOperator *Exp = cast<UnaryOperator>(E);
     switch (Exp->getOpcode()) {
index 1358d9e2a3911e52d2010b0acc328e90b17d5473..e1b0f49cc8dcf8d5758f73fdd9f16a1e4db5265b 100644 (file)
@@ -101,3 +101,30 @@ namespace PR12031 {
     f(v, [](){});
   }
 }
+
+namespace NullPtr {
+  int &f(int *p);
+  char &f(...);
+  void g() {
+    int n = 0;
+    [=] {
+      char &k = f(n); // not a null pointer constant
+    } ();
+
+    const int m = 0;
+    [=] {
+      int &k = f(m); // a null pointer constant
+    } ();
+
+    // FIXME: At least the second of these cases should probably not be
+    // considered to be a null pointer constant.
+    [=] () -> bool {
+      int &k = f(m);  // a null pointer constant?
+      return &m == 0; // no, captured!
+    } ();
+
+    [m] {
+      int &k = f(m); // a null pointer constant?
+    } ();
+  }
+}