re PR c++/13520 (gcc crashes with inheritance + default template parameter of nested...
authorKriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
Fri, 2 Jan 2004 11:41:51 +0000 (11:41 +0000)
committerKriang Lerdsuwanakij <lerdsuwa@gcc.gnu.org>
Fri, 2 Jan 2004 11:41:51 +0000 (11:41 +0000)
PR c++/13520
* cp-tree.h (DECL_UNBOUND_CLASS_TEMPLATE_P): New macro.
(DECL_FUNCTION_TEMPLATE_P): Use it.
(DECL_CLASS_TEMPLATE_P): Likewise.
* parser.c (cp_parser_lookup_name): Add is_template parameter.
(cp_parser_type_parameter): Adjust call to cp_parser_lookup_name.
(cp_parser_template_name): Likewise.
(cp_parser_elaborated_type_specifier): Likewise.
(cp_parser_namespace_name): Likewise.
(cp_parser_class_name): Likewise.
(cp_parser_lookup_name_simple): Likewise.

* g++.dg/template/qualttp22.C: New test.

From-SVN: r75321

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/qualttp22.C [new file with mode: 0644]

index e129fce9ed889bee679623fe65857289af42bf5a..fa814377cc0e1045d92e73fc9547b4f52e881c79 100644 (file)
@@ -1,2 +1,15 @@
+2004-01-02  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
+
+       PR c++/13520
+       * cp-tree.h (DECL_UNBOUND_CLASS_TEMPLATE_P): New macro.
+       (DECL_FUNCTION_TEMPLATE_P): Use it.
+       (DECL_CLASS_TEMPLATE_P): Likewise.
+       * parser.c (cp_parser_lookup_name): Add is_template parameter.
+       (cp_parser_type_parameter): Adjust call to cp_parser_lookup_name.
+       (cp_parser_template_name): Likewise.
+       (cp_parser_elaborated_type_specifier): Likewise.
+       (cp_parser_namespace_name): Likewise.
+       (cp_parser_class_name): Likewise.
+       (cp_parser_lookup_name_simple): Likewise.
 
 See ChangeLog.3 for earlier changes.
index 91e38f48223ca4dd851852b00162ae41c3783524..fb04af38785447e62ffc536748b88af69a0c3637 100644 (file)
@@ -1,6 +1,6 @@
 /* Definitions for C++ parsing and type checking.
    Copyright (C) 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
    Contributed by Michael Tiemann (tiemann@cygnus.com)
 
 This file is part of GCC.
@@ -2720,13 +2720,20 @@ struct lang_decl GTY(())
 #define DECL_TEMPLATE_TEMPLATE_PARM_P(NODE) \
   (TREE_CODE (NODE) == TEMPLATE_DECL && DECL_TEMPLATE_PARM_P (NODE))
 
+/* Nonzero if NODE is a TEMPLATE_DECL representing an
+   UNBOUND_CLASS_TEMPLATE tree node.  */
+#define DECL_UNBOUND_CLASS_TEMPLATE_P(NODE) \
+  (TREE_CODE (NODE) == TEMPLATE_DECL && !DECL_TEMPLATE_RESULT (NODE))
+
 #define DECL_FUNCTION_TEMPLATE_P(NODE)  \
   (TREE_CODE (NODE) == TEMPLATE_DECL \
+   && !DECL_UNBOUND_CLASS_TEMPLATE_P (NODE) \
    && TREE_CODE (DECL_TEMPLATE_RESULT (NODE)) == FUNCTION_DECL)
 
 /* Nonzero for a DECL that represents a template class.  */
 #define DECL_CLASS_TEMPLATE_P(NODE) \
   (TREE_CODE (NODE) == TEMPLATE_DECL \
+   && !DECL_UNBOUND_CLASS_TEMPLATE_P (NODE) \
    && TREE_CODE (DECL_TEMPLATE_RESULT (NODE)) == TYPE_DECL \
    && !DECL_TEMPLATE_TEMPLATE_PARM_P (NODE))
 
index 46907ecb5bbf7c7a922d6b7b862ad366e3132631..f66a0a80780074b5cf7cb8bc1e67f9db37418471 100644 (file)
@@ -1,5 +1,5 @@
 /* C++ Parser.
-   Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
    Written by Mark Mitchell <mark@codesourcery.com>.
 
    This file is part of GCC.
@@ -1621,7 +1621,7 @@ static void cp_parser_label_declaration
 /* Utility Routines */
 
 static tree cp_parser_lookup_name
-  (cp_parser *, tree, bool, bool, bool);
+  (cp_parser *, tree, bool, bool, bool, bool);
 static tree cp_parser_lookup_name_simple
   (cp_parser *, tree);
 static tree cp_parser_maybe_treat_template_as_class
@@ -7660,6 +7660,8 @@ cp_parser_type_parameter (cp_parser* parser)
           default-argument.  */
        if (cp_lexer_next_token_is (parser->lexer, CPP_EQ))
          {
+           bool is_template;
+
            /* Consume the `='.  */
            cp_lexer_consume_token (parser->lexer);
            /* Parse the id-expression.  */
@@ -7667,11 +7669,15 @@ cp_parser_type_parameter (cp_parser* parser)
              = cp_parser_id_expression (parser,
                                         /*template_keyword_p=*/false,
                                         /*check_dependency_p=*/true,
-                                        /*template_p=*/NULL,
+                                        /*template_p=*/&is_template,
                                         /*declarator_p=*/false);
            /* Look up the name.  */
            default_argument 
-             = cp_parser_lookup_name_simple (parser, default_argument);
+             = cp_parser_lookup_name (parser, default_argument,
+                                      /*is_type=*/false,
+                                      /*is_template=*/is_template,
+                                      /*is_namespace=*/false,
+                                      /*check_dependency=*/true);
            /* See if the default argument is valid.  */
            default_argument
              = check_template_template_default_arg (default_argument);
@@ -7979,6 +7985,7 @@ cp_parser_template_name (cp_parser* parser,
   /* Look up the name.  */
   decl = cp_parser_lookup_name (parser, identifier,
                                /*is_type=*/false,
+                               /*is_template=*/false,
                                /*is_namespace=*/false,
                                check_dependency_p);
   decl = maybe_get_template_decl_from_type_decl (decl);
@@ -8934,6 +8941,7 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
             cp_parser_lookup_name.  */
          decl = cp_parser_lookup_name (parser, identifier, 
                                        /*is_type=*/true,
+                                       /*is_template=*/false,
                                        /*is_namespace=*/false,
                                        /*check_dependency=*/true);
 
@@ -9206,6 +9214,7 @@ cp_parser_namespace_name (cp_parser* parser)
      operator.)  */
   namespace_decl = cp_parser_lookup_name (parser, identifier,
                                          /*is_type=*/false,
+                                         /*is_template=*/false,
                                          /*is_namespace=*/true,
                                          /*check_dependency=*/true);
   /* If it's not a namespace, issue an error.  */
@@ -11414,6 +11423,7 @@ cp_parser_class_name (cp_parser *parser,
          /* Look up the name.  */
          decl = cp_parser_lookup_name (parser, identifier, 
                                        type_p,
+                                       /*is_template=*/false,
                                        /*is_namespace=*/false,
                                        check_dependency_p);
        }
@@ -13245,6 +13255,9 @@ cp_parser_label_declaration (cp_parser* parser)
    If IS_TYPE is TRUE, bindings that do not refer to types are
    ignored.
 
+   If IS_TEMPLATE is TRUE, bindings that do not refer to templates are
+   ignored.
+
    If IS_NAMESPACE is TRUE, bindings that do not refer to namespaces
    are ignored.
 
@@ -13253,7 +13266,8 @@ cp_parser_label_declaration (cp_parser* parser)
 
 static tree
 cp_parser_lookup_name (cp_parser *parser, tree name, 
-                      bool is_type, bool is_namespace, bool check_dependency)
+                      bool is_type, bool is_template, bool is_namespace,
+                      bool check_dependency)
 {
   tree decl;
   tree object_type = parser->context->object_type;
@@ -13325,15 +13339,19 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
       if ((check_dependency || !CLASS_TYPE_P (parser->scope))
           && dependent_p)
        {
-         if (!is_type)
-           decl = build_nt (SCOPE_REF, parser->scope, name);
-         else
+         if (is_type)
            /* The resolution to Core Issue 180 says that `struct A::B'
               should be considered a type-name, even if `A' is
               dependent.  */
            decl = TYPE_NAME (make_typename_type (parser->scope,
                                                  name,
                                                  /*complain=*/1));
+         else if (is_template)
+           decl = TYPE_NAME (make_unbound_class_template (parser->scope,
+                                                          name,
+                                                          /*complain=*/1));
+         else
+           decl = build_nt (SCOPE_REF, parser->scope, name);
        }
       else
        {
@@ -13427,14 +13445,15 @@ cp_parser_lookup_name (cp_parser *parser, tree name,
 }
 
 /* Like cp_parser_lookup_name, but for use in the typical case where
-   CHECK_ACCESS is TRUE, IS_TYPE is FALSE, and CHECK_DEPENDENCY is
-   TRUE.  */
+   CHECK_ACCESS is TRUE, IS_TYPE is FALSE, IS_TEMPLATE is FALSE,
+   IS_NAMESPACE is FALSE, and CHECK_DEPENDENCY is TRUE.  */
 
 static tree
 cp_parser_lookup_name_simple (cp_parser* parser, tree name)
 {
   return cp_parser_lookup_name (parser, name, 
                                /*is_type=*/false,
+                               /*is_template=*/false,
                                /*is_namespace=*/false,
                                /*check_dependency=*/true);
 }
index 9a5e72658f6d562257e07bc8ec1051b4c92e3d47..55b8f033e6bc15da39b76926efc39aff64a7d2e3 100644 (file)
@@ -1,3 +1,8 @@
+2004-01-02  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
+
+       PR c++/13520
+       * g++.dg/template/qualttp22.C: New test.
+
 2004-01-01  Jan Hubicka  <jh@suse.cz>
 
        * gcc.dg/debug/20031231-1.c: New.
diff --git a/gcc/testsuite/g++.dg/template/qualttp22.C b/gcc/testsuite/g++.dg/template/qualttp22.C
new file mode 100644 (file)
index 0000000..21aa756
--- /dev/null
@@ -0,0 +1,28 @@
+// { dg-do compile }
+
+// Origin: Philippe Van Deyck <hetadres@email.com>
+
+// PR c++/13520: Default template template argument that is a qualified id
+// with dependent scope.
+
+template<typename regular_type> class Policy {};
+
+template <typename regular_type, template<typename> class OriginalPolicy>
+class ChangedPolicy_impl {};
+
+template <template<typename> class OriginalPolicy > class ChangedPolicy {
+public:
+  template<typename regular_type> class Type : public 
+  ChangedPolicy_impl<regular_type,OriginalPolicy> { };
+};
+
+template <typename regular_type, template<typename> class Policy1,
+         template<typename> class Policy2
+           = ChangedPolicy<Policy1>::template Type>
+class Host : public Policy1<regular_type>, public Policy2<regular_type> { };
+
+int main()
+{
+  Host<void, Policy> h;
+  return 0;
+}