re PR c++/11987 (Accepts-invalid with inherited nested type)
PR c++/11987 * parser.c (cp_parser_direct_declarator): Give helpful error about trying to define member of a dependent typedef. * pt.c (resolve_typename_type): Don't resolve a typedef typename. * tree.c (typedef_variant_p): New. * cp-tree.h: Declare it. From-SVN: r154149
This commit is contained in:
parent
268bab853d
commit
fc1e08468e
|
@ -1,3 +1,12 @@
|
|||
2009-11-13 Jason Merrill <jason@redhat.com>
|
||||
|
||||
PR c++/11987
|
||||
* parser.c (cp_parser_direct_declarator): Give helpful error about
|
||||
trying to define member of a dependent typedef.
|
||||
* pt.c (resolve_typename_type): Don't resolve a typedef typename.
|
||||
* tree.c (typedef_variant_p): New.
|
||||
* cp-tree.h: Declare it.
|
||||
|
||||
2009-11-12 Jason Merrill <jason@redhat.com>
|
||||
|
||||
PR c++/27078
|
||||
|
|
|
@ -5098,6 +5098,7 @@ extern bool type_has_nontrivial_copy_init (const_tree);
|
|||
extern bool class_tmpl_impl_spec_p (const_tree);
|
||||
extern int zero_init_p (const_tree);
|
||||
extern tree strip_typedefs (tree);
|
||||
extern bool typedef_variant_p (tree);
|
||||
extern tree copy_binfo (tree, tree, tree,
|
||||
tree *, int);
|
||||
extern int member_p (const_tree);
|
||||
|
|
|
@ -14191,10 +14191,17 @@ cp_parser_direct_declarator (cp_parser* parser,
|
|||
/*only_current_p=*/false);
|
||||
/* If that failed, the declarator is invalid. */
|
||||
if (TREE_CODE (type) == TYPENAME_TYPE)
|
||||
error_at (declarator_id_start_token->location,
|
||||
"%<%T::%E%> is not a type",
|
||||
TYPE_CONTEXT (qualifying_scope),
|
||||
TYPE_IDENTIFIER (qualifying_scope));
|
||||
{
|
||||
if (typedef_variant_p (type))
|
||||
error_at (declarator_id_start_token->location,
|
||||
"cannot define member of dependent typedef "
|
||||
"%qT", type);
|
||||
else
|
||||
error_at (declarator_id_start_token->location,
|
||||
"%<%T::%E%> is not a type",
|
||||
TYPE_CONTEXT (qualifying_scope),
|
||||
TYPE_IDENTIFIER (qualifying_scope));
|
||||
}
|
||||
qualifying_scope = type;
|
||||
}
|
||||
|
||||
|
|
|
@ -17689,6 +17689,9 @@ resolve_typename_type (tree type, bool only_current_p)
|
|||
to look inside it. */
|
||||
if (only_current_p && !currently_open_class (scope))
|
||||
return type;
|
||||
/* If this is a typedef, we don't want to look inside (c++/11987). */
|
||||
if (typedef_variant_p (type))
|
||||
return type;
|
||||
/* If SCOPE isn't the template itself, it will not have a valid
|
||||
TYPE_FIELDS list. */
|
||||
if (same_type_p (scope, CLASSTYPE_PRIMARY_TEMPLATE_TYPE (scope)))
|
||||
|
|
|
@ -1067,6 +1067,14 @@ strip_typedefs (tree t)
|
|||
return cp_build_qualified_type (result, cp_type_quals (t));
|
||||
}
|
||||
|
||||
/* Returns true iff TYPE is a type variant created for a typedef. */
|
||||
|
||||
bool
|
||||
typedef_variant_p (tree type)
|
||||
{
|
||||
return is_typedef_decl (TYPE_NAME (type));
|
||||
}
|
||||
|
||||
|
||||
/* Makes a copy of BINFO and TYPE, which is to be inherited into a
|
||||
graph dominated by T. If BINFO is NULL, TYPE is a dependent base,
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
2009-11-13 Jason Merrill <jason@redhat.com>
|
||||
|
||||
PR c++/11987
|
||||
* g++.dg/parse/typename11.C: New.
|
||||
* g++.dg/template/crash48.C: Adjust.
|
||||
|
||||
2009-11-13 Uros Bizjak <ubizjak@gmail.com>
|
||||
|
||||
PR testsuite/42001
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
// PR c++/11987
|
||||
|
||||
template <int dim> struct X {
|
||||
struct I { I(); };
|
||||
};
|
||||
|
||||
template <int dim> struct Y : X<dim> {
|
||||
typedef typename X<dim>::I I;
|
||||
};
|
||||
|
||||
// note: I is nested type in X, not Y!
|
||||
template <int dim>
|
||||
Y<dim>::I::I () {} // { dg-error "dependent typedef" }
|
||||
// { dg-error "no type|dependent type" "" { target *-*-* } 13 }
|
||||
|
||||
template struct Y<1>;
|
|
@ -7,4 +7,4 @@ template<typename T> struct A
|
|||
typedef typename T::X X;
|
||||
};
|
||||
|
||||
template<typename T> A<T>::X::X() {} // { dg-error "no type|invalid use|not a type" }
|
||||
template<typename T> A<T>::X::X() {} // { dg-error "no type|invalid use|not a type|dependent" }
|
||||
|
|
Loading…
Reference in New Issue