diff options
author | Mark Mitchell <mark@codesourcery.com> | 2003-01-23 06:05:20 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 2003-01-23 06:05:20 +0000 |
commit | c006d94230a09a466742fe90e2c0c58341f2da3c (patch) | |
tree | e16d681984f17ac9dd6b29a40c8e893f67bcbc22 | |
parent | 34ee7f8278d155d6d128f6af19b10ed35fa8f3d5 (diff) | |
download | gcc-c006d94230a09a466742fe90e2c0c58341f2da3c.zip gcc-c006d94230a09a466742fe90e2c0c58341f2da3c.tar.gz gcc-c006d94230a09a466742fe90e2c0c58341f2da3c.tar.bz2 |
re PR c++/9354 ([New parser?] segfault in template definition)
PR c++/9354
* init.c (build_new): Set the type of the new-expression, even
when processing_templte_decl.
PR c++/9216
* parser.c (cp_parser_primary_expression): Improve error message
for templates used in an expression context.
PR c++/8696
* parser.c (cp_parser_decl_specifier_seq): Commit to tentative
parse when encountering "typedef".
PR c++/9354
* g++.dg/parse/new1.C: New test.
PR c++/9216
* g++.dg/parse/template2.C: New test.
PR c++/9354
* g++.dg/parse/typedef2.C: New test.
From-SVN: r61643
-rw-r--r-- | gcc/cp/ChangeLog | 14 | ||||
-rw-r--r-- | gcc/cp/init.c | 3 | ||||
-rw-r--r-- | gcc/cp/parser.c | 15 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/parse/new1.C | 7 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/parse/template2.C | 7 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/parse/typedef2.C | 3 |
7 files changed, 53 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3671119..be97c50 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,17 @@ +2003-01-22 Mark Mitchell <mark@codesourcery.com> + + PR c++/9354 + * init.c (build_new): Set the type of the new-expression, even + when processing_templte_decl. + + PR c++/9216 + * parser.c (cp_parser_primary_expression): Improve error message + for templates used in an expression context. + + PR c++/8696 + * parser.c (cp_parser_decl_specifier_seq): Commit to tentative + parse when encountering "typedef". + 2003-01-22 Nathanael Nerode <neroden@gcc.gnu.org> * class.c, parser.c: ANSIfy function definitions and declarations. diff --git a/gcc/cp/init.c b/gcc/cp/init.c index c822516..493f9b8 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2024,7 +2024,8 @@ build_new (placement, decl, init, use_global_new) else t = type; - rval = build_min_nt (NEW_EXPR, placement, t, init); + rval = build_min (NEW_EXPR, build_pointer_type (type), + placement, t, init); NEW_EXPR_USE_GLOBAL (rval) = use_global_new; return rval; } diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 8e5dc33..4d809b8 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -2562,10 +2562,14 @@ cp_parser_primary_expression (cp_parser *parser, /* If we didn't find anything, or what we found was a type, then this wasn't really an id-expression. */ - if (TREE_CODE (decl) == TYPE_DECL - || TREE_CODE (decl) == NAMESPACE_DECL - || (TREE_CODE (decl) == TEMPLATE_DECL - && !DECL_FUNCTION_TEMPLATE_P (decl))) + if (TREE_CODE (decl) == TEMPLATE_DECL + && !DECL_FUNCTION_TEMPLATE_P (decl)) + { + cp_parser_error (parser, "missing template arguments"); + return error_mark_node; + } + else if (TREE_CODE (decl) == TYPE_DECL + || TREE_CODE (decl) == NAMESPACE_DECL) { cp_parser_error (parser, "expected primary-expression"); @@ -6582,6 +6586,9 @@ cp_parser_decl_specifier_seq (cp_parser* parser, cp_lexer_consume_token (parser->lexer); /* A constructor declarator cannot appear in a typedef. */ constructor_possible_p = false; + /* The "typedef" keyword can only occur in a declaration; we + may as well commit at this point. */ + cp_parser_commit_to_tentative_parse (parser); break; /* storage-class-specifier: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fb0a778..5dcd1d1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,14 @@ 2003-01-22 Mark Mitchell <mark@codesourcery.com> + PR c++/9354 + * g++.dg/parse/new1.C: New test. + + PR c++/9216 + * g++.dg/parse/template2.C: New test. + + PR c++/9354 + * g++.dg/parse/typedef2.C: New test. + PR c++/9328 * g++.dg/ext/typeof3.C: New test. diff --git a/gcc/testsuite/g++.dg/parse/new1.C b/gcc/testsuite/g++.dg/parse/new1.C new file mode 100644 index 0000000..31dad77 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/new1.C @@ -0,0 +1,7 @@ +struct T; +T* manage(T* t); +template <class Obj> struct ObjectSlot0_ { + void create() { + void* tmp = manage(new T()); + } +}; diff --git a/gcc/testsuite/g++.dg/parse/template2.C b/gcc/testsuite/g++.dg/parse/template2.C new file mode 100644 index 0000000..6689c8b --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/template2.C @@ -0,0 +1,7 @@ +namespace N { + template < typename T > class C : T {}; +} + +int main() { + N::C(); // { dg-error "template" } +} diff --git a/gcc/testsuite/g++.dg/parse/typedef2.C b/gcc/testsuite/g++.dg/parse/typedef2.C new file mode 100644 index 0000000..3ae347d --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/typedef2.C @@ -0,0 +1,3 @@ +template <typename T> struct B { typedef typename T::X X; }; +template <typename T> struct A { typedef B<T>::X::Y Z; }; // { dg-error "" } + |