Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
The r16-1019 change to special-case 'this' capture handling dropped the
'const' qualifier from the capture proxy, so the call to rvalue in
finish_this_expr no longer built a NOP_EXPR to express dropping that
'const'.
PR c++/125384
PR c++/113563
gcc/cp/ChangeLog:
* lambda.cc (build_capture_proxy): 'this' capture proxy is const.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/lambda/lambda-this23.C: New test.
---
gcc/cp/lambda.cc | 2 +-
.../g++.dg/cpp0x/lambda/lambda-this23.C | 19 +++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this23.C
diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc
index af0b66afe81..e0d676cae81 100644
--- a/gcc/cp/lambda.cc
+++ b/gcc/cp/lambda.cc
@@ -450,7 +450,7 @@ build_capture_proxy (tree member, tree init, bool early_p)
constness of the closure doesn't matter just like it doesn't matter to
other by-ref capture. It's simpler to handle this special case here
than in lambda_proxy_type. */
- type = TREE_TYPE (member);
+ type = cp_build_qualified_type (TREE_TYPE (member), TYPE_QUAL_CONST);
else
{
type = lambda_proxy_type (object);
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this23.C
b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this23.C
new file mode 100644
index 00000000000..9317a932c35
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this23.C
@@ -0,0 +1,19 @@
+// PR c++/125384
+// { dg-do compile { target c++11 } }
+
+template <class,class> struct assert_same;
+template <class T> struct assert_same<T,T> {};
+
+template<typename C>
+struct At {
+ void b() {
+ [this](){
+ assert_same <decltype (this), At*> as2;
+ }();
+ }
+};
+
+int main()
+{
+ At<int>{}.b();
+}
base-commit: 2ba702c966e3772d3d4e29e4b25beb7ef4dabf73
--
2.54.0