* 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 f1235a9de9ba031c10da708c5048ef791eb1750b..a813de7e4be0e443b2aaf54212a553a08f74f834 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 157b20d76d3348c544f2afa83ebb5ddb1b89ae4f..8bbe950828f1e6ff5b8b97b8b03f32d4a70f2f65 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();