* parser.c (cp_parser_using_declaration): Handle ellipsis and comma.
* pt.c (tsubst_decl): Handle pack expansion in USING_DECL_SCOPE.
* error.c (dump_decl): Likewise.
From-SVN: r244246
+2017-01-09 Jason Merrill <jason@redhat.com>
+
+ Implement P0195R2, C++17 variadic using.
+ * parser.c (cp_parser_using_declaration): Handle ellipsis and comma.
+ * pt.c (tsubst_decl): Handle pack expansion in USING_DECL_SCOPE.
+ * error.c (dump_decl): Likewise.
+
2017-01-09 Jakub Jelinek <jakub@redhat.com>
PR translation/79019
DEFTREECODE (UNBOUND_CLASS_TEMPLATE, "unbound_class_template", tcc_type, 0)
/* A using declaration. USING_DECL_SCOPE contains the specified
- scope. In a member using decl, unless DECL_DEPENDENT_P is true,
+ scope. In a variadic using-declaration, this is a TYPE_PACK_EXPANSION.
+ In a member using decl, unless DECL_DEPENDENT_P is true,
USING_DECL_DECLS contains the _DECL or OVERLOAD so named. This is
not an alias, but is later expanded into multiple aliases. */
DEFTREECODE (USING_DECL, "using_decl", tcc_declaration, 0)
break;
case USING_DECL:
- pp_cxx_ws_string (pp, "using");
- dump_type (pp, USING_DECL_SCOPE (t), flags);
- pp_cxx_colon_colon (pp);
- dump_decl (pp, DECL_NAME (t), flags);
+ {
+ pp_cxx_ws_string (pp, "using");
+ tree scope = USING_DECL_SCOPE (t);
+ bool variadic = false;
+ if (PACK_EXPANSION_P (scope))
+ {
+ scope = PACK_EXPANSION_PATTERN (scope);
+ variadic = true;
+ }
+ dump_type (pp, scope, flags);
+ pp_cxx_colon_colon (pp);
+ dump_decl (pp, DECL_NAME (t), flags);
+ if (variadic)
+ pp_cxx_ws_string (pp, "...");
+ }
break;
case STATIC_ASSERT:
/* Look for the `using' keyword. */
cp_parser_require_keyword (parser, RID_USING, RT_USING);
+ again:
/* Peek at the next token. */
token = cp_lexer_peek_token (parser->lexer);
/* See if it's `typename'. */
if (!cp_parser_parse_definitely (parser))
return false;
}
+ else if (cp_lexer_next_token_is (parser->lexer, CPP_ELLIPSIS))
+ {
+ cp_token *ell = cp_lexer_consume_token (parser->lexer);
+ if (cxx_dialect < cxx1z
+ && !in_system_header_at (ell->location))
+ pedwarn (ell->location, 0,
+ "pack expansion in using-declaration only available "
+ "with -std=c++1z or -std=gnu++1z");
+ qscope = make_pack_expansion (qscope);
+ }
/* The function we call to handle a using-declaration is different
depending on what scope we are in. */
if (at_class_scope_p ())
{
/* Create the USING_DECL. */
- decl = do_class_using_decl (parser->scope, identifier);
+ decl = do_class_using_decl (qscope, identifier);
if (decl && typename_p)
USING_DECL_TYPENAME_P (decl) = 1;
}
}
+ if (!access_declaration_p
+ && cp_lexer_next_token_is (parser->lexer, CPP_COMMA))
+ {
+ cp_token *comma = cp_lexer_consume_token (parser->lexer);
+ if (cxx_dialect < cxx1z)
+ pedwarn (comma->location, 0,
+ "comma-separated list in using-declaration only available "
+ "with -std=c++1z or -std=gnu++1z");
+ goto again;
+ }
+
/* Look for the final `;'. */
cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
if (DECL_DEPENDENT_P (t)
|| uses_template_parms (USING_DECL_SCOPE (t)))
{
- tree inst_scope = tsubst_copy (USING_DECL_SCOPE (t), args,
- complain, in_decl);
+ tree scope = USING_DECL_SCOPE (t);
tree name = tsubst_copy (DECL_NAME (t), args, complain, in_decl);
- r = do_class_using_decl (inst_scope, name);
- if (!r)
- r = error_mark_node;
+ if (PACK_EXPANSION_P (scope))
+ {
+ tree vec = tsubst_pack_expansion (scope, args, complain, in_decl);
+ int len = TREE_VEC_LENGTH (vec);
+ r = make_tree_vec (len);
+ for (int i = 0; i < len; ++i)
+ {
+ tree escope = TREE_VEC_ELT (vec, i);
+ tree elt = do_class_using_decl (escope, name);
+ if (!elt)
+ {
+ r = error_mark_node;
+ break;
+ }
+ else
+ {
+ TREE_PROTECTED (elt) = TREE_PROTECTED (t);
+ TREE_PRIVATE (elt) = TREE_PRIVATE (t);
+ }
+ TREE_VEC_ELT (r, i) = elt;
+ }
+ }
else
{
- TREE_PROTECTED (r) = TREE_PROTECTED (t);
- TREE_PRIVATE (r) = TREE_PRIVATE (t);
+ tree inst_scope = tsubst_copy (USING_DECL_SCOPE (t), args,
+ complain, in_decl);
+ r = do_class_using_decl (inst_scope, name);
+ if (!r)
+ r = error_mark_node;
+ else
+ {
+ TREE_PROTECTED (r) = TREE_PROTECTED (t);
+ TREE_PRIVATE (r) = TREE_PRIVATE (t);
+ }
}
}
else
--- /dev/null
+// Test for P0195R2 variadic using.
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+struct A { void f(); };
+struct B { void f(int); };
+
+template <class... Bases> struct C: Bases...
+{
+ using Bases::f...; // { dg-warning "pack expansion" "" { target c++14_down } }
+};
+
+int main()
+{
+ C<A,B> c;
+ c.f();
+ c.f(42);
+}
+
--- /dev/null
+// Test for P0195R2 multiple using.
+// { dg-options "" }
+
+namespace A {
+ int i;
+}
+
+namespace A1 {
+ using A::i, A::i; // OK: double declaration
+ // { dg-warning "comma" "" { target c++14_down } .-1 }
+}
+
+struct B {
+ int i;
+};
+
+struct X : B {
+ using B::i, B::i; // { dg-error "redeclaration" }
+ // { dg-warning "comma" "" { target c++14_down } .-1 }
+};