From 948d0d9137b8df8320cae815fd8b8aba86bcc160 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 9 Jun 2017 16:13:32 -0400 Subject: [PATCH] * constexpr.c (potential_constant_expression_1): Allow 'this' capture. From-SVN: r249077 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/constexpr.c | 2 +- gcc/testsuite/g++.dg/cpp1z/lambda-this3.C | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/lambda-this3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f1235a9de9b..a813de7e4be 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,7 @@ +2017-06-09 Jason Merrill + + * constexpr.c (potential_constant_expression_1): Allow 'this' capture. + 2017-06-09 Jan Hubicka * class.c (build_vtbl_initializer): Mark dvirt_fn as cold. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 157b20d76d3..8bbe950828f 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -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 index 00000000000..b5a1fc63a53 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/lambda-this3.C @@ -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(); -- 2.30.2