Commit c006d942 by Mark Mitchell Committed by Mark Mitchell

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
parent 34ee7f82
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> 2003-01-22 Nathanael Nerode <neroden@gcc.gnu.org>
* class.c, parser.c: ANSIfy function definitions and declarations. * class.c, parser.c: ANSIfy function definitions and declarations.
......
...@@ -2024,7 +2024,8 @@ build_new (placement, decl, init, use_global_new) ...@@ -2024,7 +2024,8 @@ build_new (placement, decl, init, use_global_new)
else else
t = type; 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; NEW_EXPR_USE_GLOBAL (rval) = use_global_new;
return rval; return rval;
} }
......
...@@ -2562,10 +2562,14 @@ cp_parser_primary_expression (cp_parser *parser, ...@@ -2562,10 +2562,14 @@ cp_parser_primary_expression (cp_parser *parser,
/* If we didn't find anything, or what we found was a type, /* If we didn't find anything, or what we found was a type,
then this wasn't really an id-expression. */ then this wasn't really an id-expression. */
if (TREE_CODE (decl) == TYPE_DECL if (TREE_CODE (decl) == TEMPLATE_DECL
|| TREE_CODE (decl) == NAMESPACE_DECL && !DECL_FUNCTION_TEMPLATE_P (decl))
|| (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, cp_parser_error (parser,
"expected primary-expression"); "expected primary-expression");
...@@ -6582,6 +6586,9 @@ cp_parser_decl_specifier_seq (cp_parser* parser, ...@@ -6582,6 +6586,9 @@ cp_parser_decl_specifier_seq (cp_parser* parser,
cp_lexer_consume_token (parser->lexer); cp_lexer_consume_token (parser->lexer);
/* A constructor declarator cannot appear in a typedef. */ /* A constructor declarator cannot appear in a typedef. */
constructor_possible_p = false; 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; break;
/* storage-class-specifier: /* storage-class-specifier:
......
2003-01-22 Mark Mitchell <mark@codesourcery.com> 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 PR c++/9328
* g++.dg/ext/typeof3.C: New test. * g++.dg/ext/typeof3.C: New test.
......
struct T;
T* manage(T* t);
template <class Obj> struct ObjectSlot0_ {
void create() {
void* tmp = manage(new T());
}
};
namespace N {
template < typename T > class C : T {};
}
int main() {
N::C(); // { dg-error "template" }
}
template <typename T> struct B { typedef typename T::X X; };
template <typename T> struct A { typedef B<T>::X::Y Z; }; // { dg-error "" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment