diff options
author | Mark Mitchell <mark@codesourcery.com> | 2004-01-05 19:54:35 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2004-01-05 19:54:35 +0000 |
commit | 8808159929f6f9b9a28975f8bddb400dcc83e6d2 (patch) | |
tree | eacfffffa6f5d9da8edcccf8bb60843d72bde99c | |
parent | 02fef8539ebbe2e8d71f1c8fcb699942e4e0cfdb (diff) | |
download | gcc-8808159929f6f9b9a28975f8bddb400dcc83e6d2.zip gcc-8808159929f6f9b9a28975f8bddb400dcc83e6d2.tar.gz gcc-8808159929f6f9b9a28975f8bddb400dcc83e6d2.tar.bz2 |
re PR c++/13451 (Wrong error message with qualified names for member declarations)
PR c++/13451
* parser.c (cp_parser_class_head): Reorder logic to check for
invalid qualification.
PR c++/13451
* g++.dg/template/class2.C: New test.
From-SVN: r75440
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/parser.c | 55 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/class2.C | 7 |
4 files changed, 47 insertions, 26 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e3baeeb..79af88e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2004-01-05 Mark Mitchell <mark@codesourcery.com> + + PR c++/13451 + * parser.c (cp_parser_class_head): Reorder logic to check for + invalid qualification. + 2004-01-04 Mark Mitchell <mark@codesourcery.com> PR c++/13157 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 76de7a0..9a16f82 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -11837,6 +11837,35 @@ cp_parser_class_head (cp_parser* parser, else if (invalid_nested_name_p) cp_parser_error (parser, "qualified name does not name a class"); + else if (nested_name_specifier) + { + tree scope; + /* Figure out in what scope the declaration is being placed. */ + scope = current_scope (); + if (!scope) + scope = current_namespace; + /* If that scope does not contain the scope in which the + class was originally declared, the program is invalid. */ + if (scope && !is_ancestor (scope, nested_name_specifier)) + { + error ("declaration of `%D' in `%D' which does not " + "enclose `%D'", type, scope, nested_name_specifier); + type = NULL_TREE; + goto done; + } + /* [dcl.meaning] + + A declarator-id shall not be qualified exception of the + definition of a ... nested class outside of its class + ... [or] a the definition or explicit instantiation of a + class member of a namespace outside of its namespace. */ + if (scope == nested_name_specifier) + { + pedwarn ("extra qualification ignored"); + nested_name_specifier = NULL_TREE; + num_templates = 0; + } + } /* An explicit-specialization must be preceded by "template <>". If it is not, try to recover gracefully. */ if (at_namespace_scope_p () @@ -11880,7 +11909,6 @@ cp_parser_class_head (cp_parser* parser, else { tree class_type; - tree scope; /* Given: @@ -11903,31 +11931,6 @@ cp_parser_class_head (cp_parser* parser, } } - /* Figure out in what scope the declaration is being placed. */ - scope = current_scope (); - if (!scope) - scope = current_namespace; - /* If that scope does not contain the scope in which the - class was originally declared, the program is invalid. */ - if (scope && !is_ancestor (scope, CP_DECL_CONTEXT (type))) - { - error ("declaration of `%D' in `%D' which does not " - "enclose `%D'", type, scope, nested_name_specifier); - type = NULL_TREE; - goto done; - } - /* [dcl.meaning] - - A declarator-id shall not be qualified exception of the - definition of a ... nested class outside of its class - ... [or] a the definition or explicit instantiation of a - class member of a namespace outside of its namespace. */ - if (scope == CP_DECL_CONTEXT (type)) - { - pedwarn ("extra qualification ignored"); - nested_name_specifier = NULL_TREE; - } - maybe_process_partial_specialization (TREE_TYPE (type)); class_type = current_class_type; /* Enter the scope indicated by the nested-name-specifier. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7e34508..fc4e462 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-01-05 Mark Mitchell <mark@codesourcery.com> + + PR c++/13451 + * g++.dg/template/class2.C: New test. + 2004-01-05 Nathan Sidwell <nathan@codesourcery.com> Richard Sandiford <rsandifo@redhat.com> diff --git a/gcc/testsuite/g++.dg/template/class2.C b/gcc/testsuite/g++.dg/template/class2.C new file mode 100644 index 0000000..4144997 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/class2.C @@ -0,0 +1,7 @@ +// PR c++/13451 + +template <class T> +struct A { + struct B; + struct A::B { }; // { dg-error "" } +}; |