+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>
PR c++/38877
parser->scope = NULL_TREE;
parser->object_scope = NULL_TREE;
parser->qualifying_scope = NULL_TREE;
+ if (processing_template_decl)
+ cp_parser_parse_tentatively (parser);
type_decl
= cp_parser_class_name (parser,
/*typename_keyword_p=*/false,
/*check_dependency=*/false,
/*class_head_p=*/false,
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
destructor is the same as the name of the qualifying
return result;
}
-/* Return the destructor denoted by OBJECT.SCOPE::~DTOR_NAME, or, if
- SCOPE is NULL, by OBJECT.~DTOR_NAME. */
+/* Return the destructor denoted by OBJECT.SCOPE::DTOR_NAME, or, if
+ SCOPE is NULL, by OBJECT.DTOR_NAME, where DTOR_NAME is ~type. */
static tree
lookup_destructor (tree object, tree scope, tree dtor_name)
scope, dtor_type);
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",
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>
PR fortran/38859
--- /dev/null
+// 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>);
+}