From: Jason Merrill Date: Sat, 23 Mar 2013 16:55:50 +0000 (-0400) Subject: re PR c++/54277 (Template class member referred to with implicit this inside lambda... X-Git-Tag: releases/gcc-4.7.3~104 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1989df72f22c19d8388a78e46bded925a9d105f6;p=thirdparty%2Fgcc.git re PR c++/54277 (Template class member referred to with implicit this inside lambda is incorrectly const-qualified) PR c++/54277 * semantics.c (lambda_capture_field_type): Don't build a magic decltype for pointer types. (lambda_proxy_type): Likewise. (finish_non_static_data_member): Get the quals from the object. From-SVN: r197009 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7cf4e6666088..b22536262b67 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2013-03-23 Jason Merrill + + PR c++/54277 + * semantics.c (lambda_capture_field_type): Don't build a + magic decltype for pointer types. + (lambda_proxy_type): Likewise. + (finish_non_static_data_member): Get the quals from + the object. + 2013-03-20 Jason Merrill PR c++/56646 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 0ad32a085180..8735c8c799d5 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1570,9 +1570,7 @@ finish_non_static_data_member (tree decl, tree object, tree qualifying_scope) else { /* Set the cv qualifiers. */ - int quals = (current_class_ref - ? cp_type_quals (TREE_TYPE (current_class_ref)) - : TYPE_UNQUALIFIED); + int quals = cp_type_quals (TREE_TYPE (object)); if (DECL_MUTABLE_P (decl)) quals &= ~TYPE_QUAL_CONST; @@ -8815,7 +8813,8 @@ tree lambda_capture_field_type (tree expr) { tree type; - if (type_dependent_expression_p (expr)) + if (type_dependent_expression_p (expr) + && !(TREE_TYPE (expr) && TREE_CODE (TREE_TYPE (expr)) == POINTER_TYPE)) { type = cxx_make_type (DECLTYPE_TYPE); DECLTYPE_TYPE_EXPR (type) = expr; @@ -9020,7 +9019,8 @@ lambda_proxy_type (tree ref) if (REFERENCE_REF_P (ref)) ref = TREE_OPERAND (ref, 0); type = TREE_TYPE (ref); - if (!dependent_type_p (type)) + if (!dependent_type_p (type) + || (type && TREE_CODE (type) == POINTER_TYPE)) return type; type = cxx_make_type (DECLTYPE_TYPE); DECLTYPE_TYPE_EXPR (type) = ref; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this9.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this9.C new file mode 100644 index 000000000000..07ddd0863de2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this9.C @@ -0,0 +1,19 @@ +// PR c++/54277 +// { dg-do compile { target c++11 } } + +struct Used +{ + void foo() { } +}; + +template +struct S +{ + Used x; + + void bar() + { + auto f = [this] { x.foo(); }; + f(); + } +};