re PR c++/34267 (ICE applying __decltype to name of template class)

PR c++/34267
	PR c++/34268
	* parser.c (cp_parser_decltype): Don't call finish_id_expression
	on ~type.
	* semantics.c (finish_decltype_type): Issue error on types, TYPE_DECLs
	and ~type early.

	* g++.dg/cpp0x/decltype7.C: New test.
	* g++.dg/cpp0x/decltype8.C: New test.

From-SVN: r130519
This commit is contained in:
Jakub Jelinek 2007-11-29 22:04:04 +01:00 committed by Jakub Jelinek
parent 10650fbb88
commit 7a547b936c
6 changed files with 54 additions and 1 deletions

View File

@ -1,3 +1,12 @@
2007-11-29 Jakub Jelinek <jakub@redhat.com>
PR c++/34267
PR c++/34268
* parser.c (cp_parser_decltype): Don't call finish_id_expression
on ~type.
* semantics.c (finish_decltype_type): Issue error on types, TYPE_DECLs
and ~type early.
2007-11-27 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/34181

View File

@ -8512,10 +8512,12 @@ cp_parser_decltype (cp_parser *parser)
/*check_dependency=*/true,
/*ambiguous_decls=*/NULL);
if (expr
if (expr
&& expr != error_mark_node
&& TREE_CODE (expr) != TEMPLATE_ID_EXPR
&& TREE_CODE (expr) != TYPE_DECL
&& (TREE_CODE (expr) != BIT_NOT_EXPR
|| !TYPE_P (TREE_OPERAND (expr, 0)))
&& cp_lexer_peek_token (parser->lexer)->type == CPP_CLOSE_PAREN)
{
/* Complete lookup of the id-expression. */

View File

@ -4066,6 +4066,15 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p)
if (!expr || error_operand_p (expr))
return error_mark_node;
if (TYPE_P (expr)
|| TREE_CODE (expr) == TYPE_DECL
|| (TREE_CODE (expr) == BIT_NOT_EXPR
&& TYPE_P (TREE_OPERAND (expr, 0))))
{
error ("argument to decltype must be an expression");
return error_mark_node;
}
if (type_dependent_expression_p (expr))
{
type = make_aggr_type (DECLTYPE_TYPE);

View File

@ -1,3 +1,10 @@
2007-11-29 Jakub Jelinek <jakub@redhat.com>
PR c++/34267
PR c++/34268
* g++.dg/cpp0x/decltype7.C: New test.
* g++.dg/cpp0x/decltype8.C: New test.
2007-11-29 Tobias Burnus <burnus@net-b.de>
PR fortran/34248

View File

@ -0,0 +1,14 @@
// PR c++/34268
// { dg-do compile }
struct A
{
__decltype (A); // { dg-error "must be an expression" }
__decltype (~A); // { dg-error "must be an expression" }
};
struct B
{
__typeof__ (B);
__typeof__ (~B); // { dg-error "expected primary-expression" }
};

View File

@ -0,0 +1,12 @@
// PR c++/34267
// { dg-do compile }
struct A {};
__decltype (A); // { dg-error "must be an expression" }
template<int> struct B
{
__decltype (A); // { dg-error "must be an expression" }
__decltype (~A); // { dg-error "must be an expression" }
__decltype (B); // { dg-error "must be an expression" }
__decltype (~B); // { dg-error "must be an expression" }
};