From 8ba658eea52678d0a049c01fbf3c3db5e32a1302 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Tue, 9 Jul 2002 23:31:28 +0000 Subject: [PATCH] cp-tree.h (constructor_name_p): Declare it. * cp-tree.h (constructor_name_p): Declare it. (check_template_template_default_arg): Likewise. * class.c (handle_using_decl): Use constructor_name_p. * decl.c (grokdeclarator): Likewise. * decl2.c (constructor_name_p): Define it. * init.c (build_member_call): Use constructor_name_p. * parse.y (template_parm): Use check_template_template_default_arg. * pt.c (check_explicit_specialization): Use constructor_name_p. * semantics.c (check_template_template_default_arg): New function. From-SVN: r55350 --- gcc/cp/ChangeLog | 12 ++++++++++++ gcc/cp/class.c | 6 ++---- gcc/cp/cp-tree.h | 3 ++- gcc/cp/decl.c | 16 ++++++---------- gcc/cp/decl2.c | 10 ++++++++++ gcc/cp/init.c | 3 +-- gcc/cp/parse.y | 9 +-------- gcc/cp/pt.c | 3 +-- gcc/cp/semantics.c | 19 +++++++++++++++++++ 9 files changed, 54 insertions(+), 27 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d4873493de7..465716da069 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,15 @@ +2002-07-09 Mark Mitchell + + * cp-tree.h (constructor_name_p): Declare it. + (check_template_template_default_arg): Likewise. + * class.c (handle_using_decl): Use constructor_name_p. + * decl.c (grokdeclarator): Likewise. + * decl2.c (constructor_name_p): Define it. + * init.c (build_member_call): Use constructor_name_p. + * parse.y (template_parm): Use check_template_template_default_arg. + * pt.c (check_explicit_specialization): Use constructor_name_p. + * semantics.c (check_template_template_default_arg): New function. + 2002-07-08 Kriang Lerdsuwanakij * pt.c (can_complete_type_without_circularity): Add static to diff --git a/gcc/cp/class.c b/gcc/cp/class.c index aa3caa13b24..f2544bd1f52 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -1212,14 +1212,12 @@ handle_using_decl (using_decl, t) if (! binfo) return; - if (name == constructor_name (ctype) - || name == constructor_name_full (ctype)) + if (constructor_name_p (name, ctype)) { cp_error_at ("`%D' names constructor", using_decl); return; } - if (name == constructor_name (t) - || name == constructor_name_full (t)) + if (constructor_name_p (name, t)) { cp_error_at ("`%D' invalid in `%T'", using_decl, t); return; diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index d92597ecbb1..6b7522fbe9d 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -3926,6 +3926,7 @@ extern tree grokoptypename PARAMS ((tree, tree)); extern void cplus_decl_attributes PARAMS ((tree *, tree, int)); extern tree constructor_name_full PARAMS ((tree)); extern tree constructor_name PARAMS ((tree)); +extern bool constructor_name_p (tree, tree); extern void defer_fn PARAMS ((tree)); extern void finish_anon_union PARAMS ((tree)); extern tree finish_table PARAMS ((tree, tree, tree, int)); @@ -4318,7 +4319,7 @@ extern void setup_vtbl_ptr PARAMS ((tree, tree)); extern void clear_out_block PARAMS ((void)); extern tree begin_global_stmt_expr PARAMS ((void)); extern tree finish_global_stmt_expr PARAMS ((tree)); - +extern tree check_template_template_default_arg (tree); /* in spew.c */ extern void init_spew PARAMS ((void)); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index a7d203ccee0..b5d18b4c67c 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -9848,10 +9848,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) if (ctype && TREE_OPERAND (decl, 0) && (TREE_CODE (TREE_OPERAND (decl, 0)) == TYPE_DECL - && ((DECL_NAME (TREE_OPERAND (decl, 0)) - == constructor_name_full (ctype)) - || (DECL_NAME (TREE_OPERAND (decl, 0)) - == constructor_name (ctype))))) + && constructor_name_p (DECL_NAME (TREE_OPERAND (decl, 0)), + ctype))) TREE_OPERAND (decl, 0) = constructor_name (ctype); next = &TREE_OPERAND (decl, 0); decl = *next; @@ -9958,10 +9956,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) } if (ctype && TREE_CODE (TREE_OPERAND (decl, 1)) == TYPE_DECL - && ((DECL_NAME (TREE_OPERAND (decl, 1)) - == constructor_name_full (ctype)) - || (DECL_NAME (TREE_OPERAND (decl, 1)) - == constructor_name (ctype)))) + && constructor_name_p (DECL_NAME (TREE_OPERAND (decl, 1)), + ctype)) TREE_OPERAND (decl, 1) = constructor_name (ctype); next = &TREE_OPERAND (decl, 1); decl = *next; @@ -9975,8 +9971,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) } else if (TREE_CODE (decl) == BIT_NOT_EXPR && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE - && (constructor_name (ctype) == TREE_OPERAND (decl, 0) - || constructor_name_full (ctype) == TREE_OPERAND (decl, 0))) + && constructor_name_p (TREE_OPERAND (decl, 0), + ctype)) { sfk = sfk_destructor; ctor_return_type = ctype; diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 7099fc25d95..4a12914695d 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1810,6 +1810,16 @@ constructor_name (thing) return thing; return t; } + +/* Returns TRUE if NAME is the name for the constructor for TYPE. */ + +bool +constructor_name_p (tree name, tree type) +{ + return (name == constructor_name (type) + || name == constructor_name_full (type)); +} + /* Defer the compilation of the FN until the end of compilation. */ diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 7f23699db41..1fa75b2521e 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1522,8 +1522,7 @@ build_member_call (type, name, parmlist) return error_mark_node; } - if (method_name == constructor_name (type) - || method_name == constructor_name_full (type)) + if (constructor_name_p (method_name, type)) return build_functional_cast (type, parmlist); if (lookup_fnfields (basetype_path, method_name, 0)) return build_method_call (decl, diff --git a/gcc/cp/parse.y b/gcc/cp/parse.y index 73eec6a45c2..e41ffc01001 100644 --- a/gcc/cp/parse.y +++ b/gcc/cp/parse.y @@ -710,14 +710,7 @@ template_parm: { $$ = build_tree_list (NULL_TREE, $1); } | template_template_parm '=' template_arg { - if (TREE_CODE ($3) != TEMPLATE_DECL - && TREE_CODE ($3) != TEMPLATE_TEMPLATE_PARM - && TREE_CODE ($3) != TYPE_DECL - && TREE_CODE ($3) != UNBOUND_CLASS_TEMPLATE) - { - error ("invalid default template argument"); - $3 = error_mark_node; - } + $3 = check_template_template_default_arg ($3); $$ = build_tree_list ($3, $1); } ; diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 358c129b255..c6d41f4ec26 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -1529,8 +1529,7 @@ check_explicit_specialization (declarator, decl, template_count, flags) tree fns = NULL_TREE; int idx; - if (name == constructor_name (ctype) - || name == constructor_name_full (ctype)) + if (constructor_name_p (name, ctype)) { int is_constructor = DECL_CONSTRUCTOR_P (decl); diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 576d931b171..8766d6fa731 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1625,6 +1625,25 @@ finish_template_template_parm (aggr, identifier) return finish_template_type_parm (aggr, tmpl); } +/* ARGUMENT is the default-argument value for a template template + parameter. If ARGUMENT is invalid, issue error messages and return + the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */ + +tree +check_template_template_default_arg (tree argument) +{ + if (TREE_CODE (argument) != TEMPLATE_DECL + && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM + && TREE_CODE (argument) != TYPE_DECL + && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE) + { + error ("invalid default template argument"); + return error_mark_node; + } + + return argument; +} + /* Finish a parameter list, indicated by PARMS. If ELLIPSIS is non-zero, the parameter list was terminated by a `...'. */