diff options
author | Jason Merrill <jason@redhat.com> | 2011-06-29 13:15:06 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2011-06-29 13:15:06 -0400 |
commit | 40d55020a382cc1836911b9702f6880b49c1d955 (patch) | |
tree | 24938062efd7fb502da82065526a9b3c36fe7213 /gcc/cp/semantics.c | |
parent | de95483d1e787c73bf1c84e47254bdab4f839762 (diff) | |
download | gcc-40d55020a382cc1836911b9702f6880b49c1d955.zip gcc-40d55020a382cc1836911b9702f6880b49c1d955.tar.gz gcc-40d55020a382cc1836911b9702f6880b49c1d955.tar.bz2 |
re PR c++/49554 ([C++0x] lambda capture causes "cannot call member function ... without object")
PR c++/49554
* semantics.c (lambda_proxy_type): New.
(build_capture_proxy): Use it.
* cp-tree.h (DECLTYPE_FOR_LAMBDA_PROXY): New.
* pt.c (tsubst) [DECLTYPE_TYPE]: Use them.
From-SVN: r175657
Diffstat (limited to 'gcc/cp/semantics.c')
-rw-r--r-- | gcc/cp/semantics.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 4581729..fb984d4 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -8489,6 +8489,27 @@ insert_pending_capture_proxies (void) LAMBDA_EXPR_PENDING_PROXIES (lam) = NULL; } +/* Given REF, a COMPONENT_REF designating a field in the lambda closure, + return the type we want the proxy to have: the type of the field itself, + with added const-qualification if the lambda isn't mutable and the + capture is by value. */ + +tree +lambda_proxy_type (tree ref) +{ + tree type; + if (REFERENCE_REF_P (ref)) + ref = TREE_OPERAND (ref, 0); + type = TREE_TYPE (ref); + if (!dependent_type_p (type)) + return type; + type = cxx_make_type (DECLTYPE_TYPE); + DECLTYPE_TYPE_EXPR (type) = ref; + DECLTYPE_FOR_LAMBDA_PROXY (type) = true; + SET_TYPE_STRUCTURAL_EQUALITY (type); + return type; +} + /* MEMBER is a capture field in a lambda closure class. Now that we're inside the operator(), build a placeholder var for future lookups and debugging. */ @@ -8496,7 +8517,7 @@ insert_pending_capture_proxies (void) tree build_capture_proxy (tree member) { - tree var, object, fn, closure, name, lam; + tree var, object, fn, closure, name, lam, type; closure = DECL_CONTEXT (member); fn = lambda_function (closure); @@ -8511,7 +8532,8 @@ build_capture_proxy (tree member) /* Remove the __ inserted by add_capture. */ name = get_identifier (IDENTIFIER_POINTER (DECL_NAME (member)) + 2); - var = build_decl (input_location, VAR_DECL, name, TREE_TYPE (object)); + type = lambda_proxy_type (object); + var = build_decl (input_location, VAR_DECL, name, type); SET_DECL_VALUE_EXPR (var, object); DECL_HAS_VALUE_EXPR_P (var) = 1; DECL_ARTIFICIAL (var) = 1; |