* constexpr.c (potential_constant_expression_1): Allow 'this' capture.
authorJason Merrill <jason@redhat.com>
Fri, 9 Jun 2017 20:13:32 +0000 (16:13 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 9 Jun 2017 20:13:32 +0000 (16:13 -0400)
From-SVN: r249077

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/cpp1z/lambda-this3.C [new file with mode: 0644]

index f1235a9..a813de7 100644 (file)
@@ -1,3 +1,7 @@
+2017-06-09  Jason Merrill  <jason@redhat.com>
+
+       * constexpr.c (potential_constant_expression_1): Allow 'this' capture.
+
 2017-06-09  Jan Hubicka  <hubicka@ucw.cz>
 
        * class.c (build_vtbl_initializer): Mark dvirt_fn as cold.
index 157b20d..8bbe950 100644 (file)
@@ -5296,7 +5296,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict,
       {
         tree x = TREE_OPERAND (t, 0);
         STRIP_NOPS (x);
-        if (is_this_parameter (x))
+        if (is_this_parameter (x) && !is_capture_proxy (x))
          {
            if (DECL_CONTEXT (x)
                && !DECL_DECLARED_CONSTEXPR_P (DECL_CONTEXT (x)))
diff --git a/gcc/testsuite/g++.dg/cpp1z/lambda-this3.C b/gcc/testsuite/g++.dg/cpp1z/lambda-this3.C
new file mode 100644 (file)
index 0000000..b5a1fc6
--- /dev/null
@@ -0,0 +1,10 @@
+// { dg-options -std=c++1z }
+
+struct S {
+  int i;
+  constexpr S() : i(5) { 
+    ([*this] () { return i + 10; }());
+  }
+  constexpr operator int() const { return i; }
+};
+constexpr int x = S();