aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2013-04-24 11:03:58 -0400
committerJason Merrill <jason@gcc.gnu.org>2013-04-24 11:03:58 -0400
commit76089b28bdc81483094af1af96bd8ec352826939 (patch)
tree3062574fc0513a27dc25fdbfccc995faeba48613
parent399bb2da17cbe7474cd38556d051e921fc74c113 (diff)
downloadgcc-76089b28bdc81483094af1af96bd8ec352826939.zip
gcc-76089b28bdc81483094af1af96bd8ec352826939.tar.gz
gcc-76089b28bdc81483094af1af96bd8ec352826939.tar.bz2
N3648: init-captures are named.
* semantics.c (add_capture): Don't prepend "__" to init-captures. (build_capture_proxy): Adjust. * error.c (dump_simple_decl): Check DECL_NORMAL_CAPTURE_P. From-SVN: r198247
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/error.c2
-rw-r--r--gcc/cp/semantics.c21
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/lambda-init6.C12
4 files changed, 33 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index c63c9e2..1c05d5d 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,10 @@
2013-04-24 Jason Merrill <jason@redhat.com>
+ N3648: init-captures are named.
+ * semantics.c (add_capture): Don't prepend "__" to init-captures.
+ (build_capture_proxy): Adjust.
+ * error.c (dump_simple_decl): Check DECL_NORMAL_CAPTURE_P.
+
N3648: Allow braced and parenthesized initializers.
* parser.c (cp_parser_lambda_introducer): Use cp_parser_initializer.
* pt.c (tsubst) [DECLTYPE_TYPE]: Handle DECLTYPE_FOR_INIT_CAPTURE.
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 7a8c0bc..4681e84 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -934,7 +934,7 @@ dump_simple_decl (tree t, tree type, int flags)
pp_string (cxx_pp, "...");
if (DECL_NAME (t))
{
- if (DECL_CLASS_SCOPE_P (t) && LAMBDA_TYPE_P (DECL_CONTEXT (t)))
+ if (TREE_CODE (t) == FIELD_DECL && DECL_NORMAL_CAPTURE_P (t))
{
pp_character (cxx_pp, '<');
pp_string (cxx_pp, IDENTIFIER_POINTER (DECL_NAME (t)) + 2);
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 4cc2259..3566739 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -9373,7 +9373,10 @@ build_capture_proxy (tree member)
object = TREE_OPERAND (object, 0);
/* Remove the __ inserted by add_capture. */
- name = get_identifier (IDENTIFIER_POINTER (DECL_NAME (member)) + 2);
+ if (DECL_NORMAL_CAPTURE_P (member))
+ name = get_identifier (IDENTIFIER_POINTER (DECL_NAME (member)) + 2);
+ else
+ name = DECL_NAME (member);
type = lambda_proxy_type (object);
var = build_decl (input_location, VAR_DECL, name, type);
@@ -9426,11 +9429,17 @@ add_capture (tree lambda, tree id, tree initializer, bool by_reference_p,
won't find the field with name lookup. We can't just leave the name
unset because template instantiation uses the name to find
instantiated fields. */
- buf = (char *) alloca (IDENTIFIER_LENGTH (id) + 3);
- buf[1] = buf[0] = '_';
- memcpy (buf + 2, IDENTIFIER_POINTER (id),
- IDENTIFIER_LENGTH (id) + 1);
- name = get_identifier (buf);
+ if (!explicit_init_p)
+ {
+ buf = (char *) alloca (IDENTIFIER_LENGTH (id) + 3);
+ buf[1] = buf[0] = '_';
+ memcpy (buf + 2, IDENTIFIER_POINTER (id),
+ IDENTIFIER_LENGTH (id) + 1);
+ name = get_identifier (buf);
+ }
+ else
+ /* But captures with explicit initializers are named. */
+ name = id;
/* If TREE_TYPE isn't set, we're still in the introducer, so check
for duplicates. */
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-init6.C b/gcc/testsuite/g++.dg/cpp1y/lambda-init6.C
new file mode 100644
index 0000000..3ebf479
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/lambda-init6.C
@@ -0,0 +1,12 @@
+// Test that simple captures are not named in the closure type, but
+// initialized captures are named.
+// { dg-options "-std=c++1y" }
+
+int main()
+{
+ int i;
+ auto lam = [i,j=42]{};
+ lam.j;
+ lam.j.foo; // { dg-error "::j" }
+ lam.i; // { dg-error "no member" }
+}