aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2003-02-24 07:43:23 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>2003-02-24 07:43:23 +0000
commitca099ac8c57c9858373cf83befdfae7bab8e4a4e (patch)
tree85612b52e4377cb1291b4fccdef603a8f787b9cb
parent463f02cd037fbf3af66cdbfff526fcb48d2ba746 (diff)
downloadgcc-ca099ac8c57c9858373cf83befdfae7bab8e4a4e.zip
gcc-ca099ac8c57c9858373cf83befdfae7bab8e4a4e.tar.gz
gcc-ca099ac8c57c9858373cf83befdfae7bab8e4a4e.tar.bz2
re PR c++/5333 (ICE on nested template classes using other nested template classes)
PR c++/5333 * cp-tree.h (CLASSTYPE_PRIMARY_TEMPLATE): New macro. * parser.c (cp_parser_diagnose_invalid_type_name): Use it. * pt.c (instantiate_class_template): Don't try to instantiate dependent types. (resolve_typename_type): Use CLASSTYPE_PRIMARY_TEMPLATE. PR c++/5333 * g++.dg/parse/fused-params1.C: Adjust error messages. * g++.dg/template/nested3.C: New test. From-SVN: r63354
-rw-r--r--gcc/cp/ChangeLog9
-rw-r--r--gcc/cp/cp-tree.h6
-rw-r--r--gcc/cp/parser.c6
-rw-r--r--gcc/cp/pt.c8
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/parse/fused-params1.C4
-rw-r--r--gcc/testsuite/g++.dg/template/nested3.C28
7 files changed, 60 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 00be1dd..20e1f22 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,12 @@
+2003-02-23 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/5333
+ * cp-tree.h (CLASSTYPE_PRIMARY_TEMPLATE): New macro.
+ * parser.c (cp_parser_diagnose_invalid_type_name): Use it.
+ * pt.c (instantiate_class_template): Don't try to instantiate
+ dependent types.
+ (resolve_typename_type): Use CLASSTYPE_PRIMARY_TEMPLATE.
+
2003-02-21 Mark Mitchell <mark@codesourcery.com>
PR c++/9749
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index e463fb4..919e529 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -2316,6 +2316,12 @@ struct lang_decl GTY(())
#define ENUM_TI_ARGS(NODE) \
TI_ARGS (ENUM_TEMPLATE_INFO (NODE))
+/* For a template instantiation TYPE, returns the TYPE corresponding
+ to the primary template. */
+#define CLASSTYPE_PRIMARY_TEMPLATE_TYPE(TYPE) \
+ TREE_TYPE (DECL_TEMPLATE_RESULT (DECL_PRIMARY_TEMPLATE \
+ (CLASSTYPE_TI_TEMPLATE ((TYPE)))))
+
/* Like DECL_TI_TEMPLATE, but for an ENUMERAL_, RECORD_, or UNION_TYPE. */
#define TYPE_TI_TEMPLATE(NODE) \
(TI_TEMPLATE (TYPE_TEMPLATE_INFO (NODE)))
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 79ec8be..0688cdc 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -1954,10 +1954,7 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser)
template (which will have an empty TYPE_FIELDs),
to the main version. */
if (CLASSTYPE_USE_TEMPLATE (base_type))
- base_type = (TREE_TYPE
- (DECL_TEMPLATE_RESULT
- (DECL_PRIMARY_TEMPLATE
- (CLASSTYPE_TI_TEMPLATE (base_type)))));
+ base_type = CLASSTYPE_PRIMARY_TEMPLATE_TYPE (base_type);
for (field = TYPE_FIELDS (base_type);
field;
field = TREE_CHAIN (field))
@@ -4526,6 +4523,7 @@ cp_parser_unary_operator (cp_token* token)
/* Parse a new-expression.
+ new-expression:
:: [opt] new new-placement [opt] new-type-id new-initializer [opt]
:: [opt] new new-placement [opt] ( type-id ) new-initializer [opt]
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index add427d..36ae04d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -5151,7 +5151,9 @@ instantiate_class_template (type)
if (type == error_mark_node)
return error_mark_node;
- if (TYPE_BEING_DEFINED (type) || COMPLETE_TYPE_P (type))
+ if (TYPE_BEING_DEFINED (type)
+ || COMPLETE_TYPE_P (type)
+ || dependent_type_p (type))
return type;
/* Figure out which template is being instantiated. */
@@ -11526,6 +11528,10 @@ resolve_typename_type (tree type, bool only_current_p)
to look inside it. */
if (only_current_p && !currently_open_class (scope))
return error_mark_node;
+ /* If SCOPE is a partial instantiation, it will not have a valid
+ TYPE_FIELDS list, so use the original template. */
+ if (CLASSTYPE_USE_TEMPLATE (scope))
+ scope = CLASSTYPE_PRIMARY_TEMPLATE_TYPE (scope);
/* Enter the SCOPE so that name lookup will be resolved as if we
were in the class definition. In particular, SCOPE will no
longer be considered a dependent type. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 73c1e5e..3dad6fd 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2003-02-23 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/5333
+ * g++.dg/parse/fused-params1.C: Adjust error messages.
+ * g++.dg/template/nested3.C: New test.
+
2003-02-24 Alan Modra <amodra@bigpond.net.au>
* g++.dg/abi/param1.C: New test.
diff --git a/gcc/testsuite/g++.dg/parse/fused-params1.C b/gcc/testsuite/g++.dg/parse/fused-params1.C
index 2e9378d..adb47a0 100644
--- a/gcc/testsuite/g++.dg/parse/fused-params1.C
+++ b/gcc/testsuite/g++.dg/parse/fused-params1.C
@@ -3,9 +3,9 @@
// { dg-do compile }
template <int N,typename T> struct A
-{
+{ // { dg-error "" }
typedef T X;
- template <int M> void foo (const A<M,X>&); // { dg-error "candidate" }
+ template <int M> void foo (const A<M,X>&);
};
template <int N,int M,typename T>
diff --git a/gcc/testsuite/g++.dg/template/nested3.C b/gcc/testsuite/g++.dg/template/nested3.C
new file mode 100644
index 0000000..1c45d64
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/nested3.C
@@ -0,0 +1,28 @@
+template <class T1, class T2>
+class A {
+ template <class S>
+ class SubA {
+ int _k;
+ };
+ T1 _t1;
+ T2 _t2;
+};
+
+template <class U>
+class B {
+ class SubB1 {
+ B _i;
+ };
+
+ class SubB2 {
+ int _j;
+ };
+ A<U,SubB1>::SubA<SubB2> _a; // { dg-error "" }
+};
+
+
+int main() {
+ B<char> objB;
+
+ return 0;
+}