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.
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);
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);
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. */
--- /dev/null
+// 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" }
+}