aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/cp/lambda.cc3
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const11.C14
2 files changed, 17 insertions, 0 deletions
diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc
index 212990a..9925209 100644
--- a/gcc/cp/lambda.cc
+++ b/gcc/cp/lambda.cc
@@ -1760,6 +1760,9 @@ prune_lambda_captures (tree body)
if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam) == CPLD_NONE)
/* No default captures, and we don't prune explicit captures. */
return;
+ /* Don't bother pruning in a template, we'll prune at instantiation time. */
+ if (dependent_type_p (TREE_TYPE (lam)))
+ return;
hash_map<tree,tree*> const_vars;
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const11.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const11.C
new file mode 100644
index 0000000..26af75b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const11.C
@@ -0,0 +1,14 @@
+// PR c++/108975
+// { dg-do compile { target c++11 } }
+
+template<class T>
+void f() {
+ constexpr int dim = 1;
+ auto l = [&] {
+ int n[dim * 1];
+ };
+ // In f<int>, we shouldn't actually capture dim.
+ static_assert (sizeof(l) == 1, "");
+}
+
+template void f<int>();