diff options
author | Giovanni Bajo <giovannibajo@gcc.gnu.org> | 2004-06-06 02:08:18 +0000 |
---|---|---|
committer | Giovanni Bajo <giovannibajo@gcc.gnu.org> | 2004-06-06 02:08:18 +0000 |
commit | 8a83a69363442100aa9435199e5d385716658255 (patch) | |
tree | 39d1906c627b576837b2b1315db0bf6b3a081b79 /gcc | |
parent | ad94c84603832382465e4e1ed0e10b5595a30a66 (diff) | |
download | gcc-8a83a69363442100aa9435199e5d385716658255.zip gcc-8a83a69363442100aa9435199e5d385716658255.tar.gz gcc-8a83a69363442100aa9435199e5d385716658255.tar.bz2 |
re PR c++/15503 (nested template problem)
PR c++/15503
* parser.c (cp_parser_mem_initializer_id): Gracefully reject
'typename', and accept 'template'.
PR c++/15503
* g++.dg/template/meminit2.C: New test.
From-SVN: r82660
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/parser.c | 12 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/meminit2.C | 21 |
4 files changed, 43 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 75aa42f..8ec1302 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2004-06-06 Giovanni Bajo <giovannibajo@gcc.gnu.org> + + PR c++/15503 + * parser.c (cp_parser_mem_initializer_id): Gracefully reject + 'typename', and accept 'template'. + 2004-06-03 Andrew Pinski <pinskia@physics.uc.edu> Jan Hubicka <jh@suse.cz> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index d7253f0..0c94f71 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -7383,8 +7383,16 @@ cp_parser_mem_initializer_id (cp_parser* parser) { bool global_scope_p; bool nested_name_specifier_p; + bool template_p = false; tree id; + /* `typename' is not allowed in this context ([temp.res]). */ + if (cp_lexer_next_token_is_keyword (parser->lexer, RID_TYPENAME)) + { + error ("keyword `typename' not allowed in this context (a qualified " + "member initializer is implicitly a type)"); + cp_lexer_consume_token (parser->lexer); + } /* Look for the optional `::' operator. */ global_scope_p = (cp_parser_global_scope_opt (parser, @@ -7409,12 +7417,14 @@ cp_parser_mem_initializer_id (cp_parser* parser) /*type_p=*/true, /*is_declaration=*/true) != NULL_TREE); + if (nested_name_specifier_p) + template_p = cp_parser_optional_template_keyword (parser); /* If there is a `::' operator or a nested-name-specifier, then we are definitely looking for a class-name. */ if (global_scope_p || nested_name_specifier_p) return cp_parser_class_name (parser, /*typename_keyword_p=*/true, - /*template_keyword_p=*/false, + /*template_keyword_p=*/template_p, /*type_p=*/false, /*check_dependency_p=*/true, /*class_head_p=*/false, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d316dfc..197242d2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-06-06 Giovanni Bajo <giovannibajo@gcc.gnu.org> + + PR c++/15503 + * g++.dg/template/meminit2.C: New test. + 2004-06-04 Paolo Bonzini <bonzini@gnu.org> PR target/15822 diff --git a/gcc/testsuite/g++.dg/template/meminit2.C b/gcc/testsuite/g++.dg/template/meminit2.C new file mode 100644 index 0000000..6abf2df --- /dev/null +++ b/gcc/testsuite/g++.dg/template/meminit2.C @@ -0,0 +1,21 @@ +// { dg-do compile } +// Origin: Mark Anders <mark dot a dot anders at intel dot com> +// PR c++/15503: disambiguators in base classes and mem-initializers + +template <typename K1> struct O { + template <typename K2> struct I {}; +}; + +template <typename T> +struct A : typename O<T>::template I<int> { // { dg-error "keyword `typename' not allowed" } + A() : typename O<T>::template I<int>() // { dg-error "keyword `typename' not allowed" } + {}; +}; + +template <typename T> +struct B : O<T>::template I<int> { + B() : O<T>::I<int>() // { dg-error "used as template|it is a template" "" } + {}; +}; + +// { dg-bogus "end of input" "bogus token skipping in the parser" { xfail *-*-* } 17 } |