PR c++/86147 - wrong capture for template argument.
authorJason Merrill <jason@redhat.com>
Sat, 16 Jun 2018 06:35:53 +0000 (02:35 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Sat, 16 Jun 2018 06:35:53 +0000 (02:35 -0400)
* expr.c (mark_use): Look through NOP_EXPR.

From-SVN: r261676

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

index 56fe205fdbc2863676c3d1ab6ca010ed43ee2902..2e341f105276589e12b40f6fc3f60ffb88b9ceec 100644 (file)
@@ -1,5 +1,8 @@
 2018-06-15  Jason Merrill  <jason@redhat.com>
 
+       PR c++/86147 - wrong capture for template argument.
+       * expr.c (mark_use): Look through NOP_EXPR.
+
        * name-lookup.c (do_pushtag): Don't look through complete types, but
        don't add to them either.  Get context from current_binding_level.
        * pt.c (tsubst_default_argument): Use push_to/pop_from_top_level.
index 9780b75d1cd3501db29e2bac12f7d9a057b9ca74..133a01b8a51443c417833ef029f293fbcb4af9b7 100644 (file)
@@ -186,12 +186,15 @@ mark_use (tree expr, bool rvalue_p, bool read_p,
            expr = convert_from_reference (r);
        }
       break;
-    default:
+
+    CASE_CONVERT:
+    case VIEW_CONVERT_EXPR:
       if (location_wrapper_p (expr))
-       {
-         loc = EXPR_LOCATION (expr);
-         recurse_op[0] = true;
-       }
+       loc = EXPR_LOCATION (expr);
+      recurse_op[0] = true;
+      break;
+
+    default:
       break;
     }
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const9.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const9.C
new file mode 100644 (file)
index 0000000..0724ae1
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/86147
+// { dg-do compile { target c++11 } }
+
+template <class T, T N> struct X { };
+
+struct A { static constexpr int value = 0; };
+
+template<class C>
+void foo() {
+    constexpr int N = C::value;
+    auto f = [&]{  X<int, N> a; };
+}
+
+int main() { 
+    foo<A>();
+    return 0;
+}