From ca099ac8c57c9858373cf83befdfae7bab8e4a4e Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Mon, 24 Feb 2003 07:43:23 +0000 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 9 +++++++ gcc/cp/cp-tree.h | 6 +++++ gcc/cp/parser.c | 6 ++--- gcc/cp/pt.c | 8 ++++++- gcc/testsuite/ChangeLog | 6 +++++ gcc/testsuite/g++.dg/parse/fused-params1.C | 4 ++-- gcc/testsuite/g++.dg/template/nested3.C | 28 ++++++++++++++++++++++ 7 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/nested3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 00be1dd8f30..20e1f22aabe 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2003-02-23 Mark Mitchell + + 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 PR c++/9749 diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index e463fb4b68c..919e5291f1a 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 79ec8be6417..0688cdcc86c 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 add427d4ed1..36ae04d14d9 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 73c1e5e2488..3dad6fde31b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2003-02-23 Mark Mitchell + + PR c++/5333 + * g++.dg/parse/fused-params1.C: Adjust error messages. + * g++.dg/template/nested3.C: New test. + 2003-02-24 Alan Modra * 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 2e9378d93e1..adb47a0522a 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 struct A -{ +{ // { dg-error "" } typedef T X; - template void foo (const A&); // { dg-error "candidate" } + template void foo (const A&); }; template diff --git a/gcc/testsuite/g++.dg/template/nested3.C b/gcc/testsuite/g++.dg/template/nested3.C new file mode 100644 index 00000000000..1c45d645290 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/nested3.C @@ -0,0 +1,28 @@ +template +class A { + template + class SubA { + int _k; + }; + T1 _t1; + T2 _t2; +}; + +template +class B { + class SubB1 { + B _i; + }; + + class SubB2 { + int _j; + }; + A::SubA _a; // { dg-error "" } +}; + + +int main() { + B objB; + + return 0; +} -- 2.30.2