Commit 05134211 by Jason Merrill Committed by Jason Merrill

re PR c++/23287 (Explicitly invoking destructor of template class in a template and is dependent)

        PR c++/23287
        * parser.c (cp_parser_unqualified_id): In a template,
        accept ~identifier.
        * typeck.c (lookup_destructor): Handle IDENTIFIER_NODE.

From-SVN: r143502
parent 9295d9ed
2009-01-19 Jason Merrill <jason@redhat.com>
PR c++/23287
* parser.c (cp_parser_unqualified_id): In a template,
accept ~identifier.
* typeck.c (lookup_destructor): Handle IDENTIFIER_NODE.
2009-01-16 Jason Merrill <jason@redhat.com> 2009-01-16 Jason Merrill <jason@redhat.com>
PR c++/38877 PR c++/38877
......
...@@ -3880,6 +3880,8 @@ cp_parser_unqualified_id (cp_parser* parser, ...@@ -3880,6 +3880,8 @@ cp_parser_unqualified_id (cp_parser* parser,
parser->scope = NULL_TREE; parser->scope = NULL_TREE;
parser->object_scope = NULL_TREE; parser->object_scope = NULL_TREE;
parser->qualifying_scope = NULL_TREE; parser->qualifying_scope = NULL_TREE;
if (processing_template_decl)
cp_parser_parse_tentatively (parser);
type_decl type_decl
= cp_parser_class_name (parser, = cp_parser_class_name (parser,
/*typename_keyword_p=*/false, /*typename_keyword_p=*/false,
...@@ -3888,6 +3890,14 @@ cp_parser_unqualified_id (cp_parser* parser, ...@@ -3888,6 +3890,14 @@ cp_parser_unqualified_id (cp_parser* parser,
/*check_dependency=*/false, /*check_dependency=*/false,
/*class_head_p=*/false, /*class_head_p=*/false,
declarator_p); declarator_p);
if (processing_template_decl
&& ! cp_parser_parse_definitely (parser))
{
/* We couldn't find a type with this name, so just accept
it and check for a match at instantiation time. */
type_decl = cp_parser_identifier (parser);
return build_nt (BIT_NOT_EXPR, type_decl);
}
} }
/* If an error occurred, assume that the name of the /* If an error occurred, assume that the name of the
destructor is the same as the name of the qualifying destructor is the same as the name of the qualifying
......
...@@ -2101,8 +2101,8 @@ build_class_member_access_expr (tree object, tree member, ...@@ -2101,8 +2101,8 @@ build_class_member_access_expr (tree object, tree member,
return result; return result;
} }
/* Return the destructor denoted by OBJECT.SCOPE::~DTOR_NAME, or, if /* Return the destructor denoted by OBJECT.SCOPE::DTOR_NAME, or, if
SCOPE is NULL, by OBJECT.~DTOR_NAME. */ SCOPE is NULL, by OBJECT.DTOR_NAME, where DTOR_NAME is ~type. */
static tree static tree
lookup_destructor (tree object, tree scope, tree dtor_name) lookup_destructor (tree object, tree scope, tree dtor_name)
...@@ -2117,7 +2117,21 @@ lookup_destructor (tree object, tree scope, tree dtor_name) ...@@ -2117,7 +2117,21 @@ lookup_destructor (tree object, tree scope, tree dtor_name)
scope, dtor_type); scope, dtor_type);
return error_mark_node; return error_mark_node;
} }
if (!DERIVED_FROM_P (dtor_type, TYPE_MAIN_VARIANT (object_type))) if (TREE_CODE (dtor_type) == IDENTIFIER_NODE)
{
/* In a template, names we can't find a match for are still accepted
destructor names, and we check them here. */
if (check_dtor_name (object_type, dtor_type))
dtor_type = object_type;
else
{
error ("object type %qT does not match destructor name ~%qT",
object_type, dtor_type);
return error_mark_node;
}
}
else if (!DERIVED_FROM_P (dtor_type, TYPE_MAIN_VARIANT (object_type)))
{ {
error ("the type being destroyed is %qT, but the destructor refers to %qT", error ("the type being destroyed is %qT, but the destructor refers to %qT",
TYPE_MAIN_VARIANT (object_type), dtor_type); TYPE_MAIN_VARIANT (object_type), dtor_type);
......
2009-01-19 Jason Merrill <jason@redhat.com>
PR c++/23287
* g++.dg/template/dtor5.C: New test.
2009-01-19 Mikael Morin <mikael.morin@tele2.fr> 2009-01-19 Mikael Morin <mikael.morin@tele2.fr>
PR fortran/38859 PR fortran/38859
......
// PR c++/23287
template <class T> struct A
{
int i;
~A();
};
template <class T> void f(A<T> *ap) {
ap->~A();
}
template <class T> void g(A<T> *ap) {
ap->~B(); // { dg-error "destructor name" }
}
int main()
{
f(new A<int>);
g(new A<int>);
}
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