PR c++/85761 - ICE with ill-formed use of const outer variable.
authorJason Merrill <jason@redhat.com>
Sun, 3 Jun 2018 01:01:47 +0000 (21:01 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Sun, 3 Jun 2018 01:01:47 +0000 (21:01 -0400)
* expr.c (mark_use): Handle location wrappers.

From-SVN: r261121

gcc/cp/ChangeLog
gcc/cp/expr.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const8.C [new file with mode: 0644]

index bbf76eabb15e66f46dac78c333ed257d1f4850a5..c661d46c99a72ad10bdc0de7ca18b830b01e5692 100644 (file)
@@ -1,3 +1,8 @@
+2018-06-02  Jason Merrill  <jason@redhat.com>
+
+       PR c++/85761 - ICE with ill-formed use of const outer variable.
+       * expr.c (mark_use): Handle location wrappers.
+
 2018-06-01  Jason Merrill  <jason@redhat.com>
 
        PR c++/85764 - bogus 'this' not captured error.
index 0d0a10ec4a6388f5cf28e7aaca3faf1da2af6a1b..9780b75d1cd3501db29e2bac12f7d9a057b9ca74 100644 (file)
@@ -139,6 +139,9 @@ mark_use (tree expr, bool rvalue_p, bool read_p,
                  break;
                }
            }
+         temp_override<location_t> l (input_location);
+         if (loc != UNKNOWN_LOCATION)
+           input_location = loc;
          expr = process_outer_var_ref (expr, tf_warning_or_error, true);
          if (!(TREE_TYPE (oexpr)
                && TYPE_REF_P (TREE_TYPE (oexpr))))
@@ -184,6 +187,11 @@ mark_use (tree expr, bool rvalue_p, bool read_p,
        }
       break;
     default:
+      if (location_wrapper_p (expr))
+       {
+         loc = EXPR_LOCATION (expr);
+         recurse_op[0] = true;
+       }
       break;
     }
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const8.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const8.C
new file mode 100644 (file)
index 0000000..41cfd43
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/85761
+// { dg-do compile { target c++11 } }
+
+template <typename T>
+void out(const T& value);
+
+struct foo {
+  void bar();
+};
+
+void foo::bar()
+{
+  constexpr int COUNT = 10000;
+  auto run = []() {
+    out(COUNT);                // { dg-error "9:not captured" }
+  };
+
+  run();
+}