This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++0x] Variadic templates with using declarations, attributes (PR c++/34051)
- From: "Doug Gregor" <doug dot gregor at gmail dot com>
- To: "GCC Patches" <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 4 Dec 2007 23:57:28 -0500
- Subject: [C++0x] Variadic templates with using declarations, attributes (PR c++/34051)
The attached patch fixes PR c++/34051, a P2 where we failed to
properly check for bare parameter packs in using declarations and
declaration attributes. This patch fixes both the ICE and produces
appropriate diagnostics for the ill-formed examples in the PR.
Tested i686-pc-linux-gnu. Okay for mainline?
- Doug
2007-12-04 Douglas Gregor <doug.gregor@gmail.com>
PR c++/34051
* tree.c (cp_walk_subtrees): Walk USING_DECL nodes.
* pt.c (find_parameter_packs_r): Look at the type of
IDENTIFIER_NODEs (e.g., for user-defined conversions).
* semantics.c (finish_member_declaration): Check the attributes of
the declaration for bare parameter packs.
* parser.c (cp_parser_using_declaration): Check the using
declaration for bare parameter packs.
2007-12-04 Douglas Gregor <doug.gregor@gmail.com>
PR c++/34051
* testsuite/g++.dg/cpp0x/vt-34051.C: New.
* testsuite/g++.dg/cpp0x/vt-34051-2.C: New.
Index: cp/tree.c
===================================================================
--- cp/tree.c (revision 130615)
+++ cp/tree.c (working copy)
@@ -2351,6 +2351,13 @@ cp_walk_subtrees (tree *tp, int *walk_su
*walk_subtrees_p = 0;
break;
+ case USING_DECL:
+ WALK_SUBTREE (DECL_NAME (*tp));
+ WALK_SUBTREE (USING_DECL_SCOPE (*tp));
+ WALK_SUBTREE (USING_DECL_DECLS (*tp));
+ *walk_subtrees_p = 0;
+ break;
+
case RECORD_TYPE:
if (TYPE_PTRMEMFUNC_P (*tp))
WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp));
Index: cp/pt.c
===================================================================
--- cp/pt.c (revision 130615)
+++ cp/pt.c (working copy)
@@ -2576,6 +2576,11 @@ recheck:
*walk_subtrees = 0;
return NULL_TREE;
+ case IDENTIFIER_NODE:
+ cp_walk_tree (&TREE_TYPE (t), &find_parameter_packs_r, ppd, NULL);
+ *walk_subtrees = 0;
+ return NULL_TREE;
+
default:
return NULL_TREE;
}
Index: cp/semantics.c
===================================================================
--- cp/semantics.c (revision 130615)
+++ cp/semantics.c (working copy)
@@ -2321,7 +2321,10 @@ finish_member_declaration (tree decl)
/* Check for bare parameter packs in the member variable declaration. */
if (TREE_CODE (decl) == FIELD_DECL)
- check_for_bare_parameter_packs (&TREE_TYPE (decl));
+ {
+ check_for_bare_parameter_packs (&TREE_TYPE (decl));
+ check_for_bare_parameter_packs (&DECL_ATTRIBUTES (decl));
+ }
/* [dcl.link]
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 130615)
+++ cp/parser.c (working copy)
@@ -11744,14 +11744,20 @@ cp_parser_using_declaration (cp_parser*
{
/* Create the USING_DECL. */
decl = do_class_using_decl (parser->scope, identifier);
- /* Add it to the list of members in this class. */
- finish_member_declaration (decl);
+
+ if (check_for_bare_parameter_packs (&decl))
+ /* Add it to the list of members in this class. */
+ finish_member_declaration (decl);
+ else
+ return false;
}
else
{
decl = cp_parser_lookup_name_simple (parser, identifier);
if (decl == error_mark_node)
cp_parser_name_lookup_error (parser, identifier, decl, NULL);
+ else if (!check_for_bare_parameter_packs (&decl))
+ return false;
else if (!at_namespace_scope_p ())
do_local_using_decl (decl, qscope, identifier);
else
Index: testsuite/g++.dg/cpp0x/vt-34051-2.C
===================================================================
--- testsuite/g++.dg/cpp0x/vt-34051-2.C (revision 0)
+++ testsuite/g++.dg/cpp0x/vt-34051-2.C (revision 0)
@@ -0,0 +1,7 @@
+// { dg-options "-std=c++0x" }
+template<typename... T> struct A
+{
+ int i __attribute__((aligned(__alignof(T)))); // { dg-error "parameter packs|T|requested" }
+};
+
+A<int> a; // { dg-error "from here" }
Index: testsuite/g++.dg/cpp0x/vt-34051.C
===================================================================
--- testsuite/g++.dg/cpp0x/vt-34051.C (revision 0)
+++ testsuite/g++.dg/cpp0x/vt-34051.C (revision 0)
@@ -0,0 +1,12 @@
+// { dg-options "-std=c++0x" }
+struct A
+{
+ operator int();
+};
+
+template <typename... T> struct B : A
+{
+ using A::operator T; // { dg-error "parameter packs|T" }
+};
+
+B<int> b;