re PR c++/30302 (ICE with invalid member in anonymous struct)

/cp
2007-09-03  Paolo Carlini  <pcarlini@suse.de>

	PR c++/30302
	* semantics.c (finish_id_expression): Check that path != NULL_TREE
	before using TYPE_BINFO on it.
	* class.c (finish_struct_anon): Deal correctly with anonymous
	structs (vs unions, as GNU extension) in error messages.

/testsuite
2007-09-03  Paolo Carlini  <pcarlini@suse.de>

	PR c++/30302
	* g++.dg/ext/anon-struct5.C: New.

From-SVN: r128145
This commit is contained in:
Paolo Carlini 2007-09-05 19:10:48 +00:00 committed by Paolo Carlini
parent 13678df87b
commit 61fdc9d746
5 changed files with 46 additions and 5 deletions

View File

@ -1,3 +1,11 @@
2007-09-05 Paolo Carlini <pcarlini@suse.de>
PR c++/30302
* semantics.c (finish_id_expression): Use context_for_name_lookup
insted of DECL_CONTEXT, to see through anonymous structs and unions.
* class.c (finish_struct_anon): Deal correctly with anonymous
structs (vs unions, as GNU extension) in error messages.
2007-09-05 Jan Hubicka <jh@suse.cz>
* cp/sematics.c (expand_body): Remove unnecesary import_export_decl

View File

@ -2458,6 +2458,7 @@ finish_struct_anon (tree t)
if (DECL_NAME (field) == NULL_TREE
&& ANON_AGGR_TYPE_P (TREE_TYPE (field)))
{
bool is_union = TREE_CODE (TREE_TYPE (field)) == UNION_TYPE;
tree elt = TYPE_FIELDS (TREE_TYPE (field));
for (; elt; elt = TREE_CHAIN (elt))
{
@ -2475,15 +2476,29 @@ finish_struct_anon (tree t)
if (TREE_CODE (elt) != FIELD_DECL)
{
pedwarn ("%q+#D invalid; an anonymous union can "
"only have non-static data members", elt);
if (is_union)
pedwarn ("%q+#D invalid; an anonymous union can "
"only have non-static data members", elt);
else
pedwarn ("%q+#D invalid; an anonymous struct can "
"only have non-static data members", elt);
continue;
}
if (TREE_PRIVATE (elt))
pedwarn ("private member %q+#D in anonymous union", elt);
{
if (is_union)
pedwarn ("private member %q+#D in anonymous union", elt);
else
pedwarn ("private member %q+#D in anonymous struct", elt);
}
else if (TREE_PROTECTED (elt))
pedwarn ("protected member %q+#D in anonymous union", elt);
{
if (is_union)
pedwarn ("protected member %q+#D in anonymous union", elt);
else
pedwarn ("protected member %q+#D in anonymous struct", elt);
}
TREE_PRIVATE (elt) = TREE_PRIVATE (field);
TREE_PROTECTED (elt) = TREE_PROTECTED (field);

View File

@ -2928,7 +2928,7 @@ finish_id_expression (tree id_expression,
{
if (DECL_P (decl) && DECL_NONLOCAL (decl)
&& DECL_CLASS_SCOPE_P (decl)
&& DECL_CONTEXT (decl) != current_class_type)
&& context_for_name_lookup (decl) != current_class_type)
{
tree path;

View File

@ -1,3 +1,8 @@
2007-09-05 Paolo Carlini <pcarlini@suse.de>
PR c++/30302
* g++.dg/ext/anon-struct5.C: New.
2007-09-05 Uros Bizjak <ubizjak@gmail.com>
* gcc.dg/i386-cpuid.h: Remove.

View File

@ -0,0 +1,13 @@
// PR c++/30302
struct A
{
struct { static int i; }; // { dg-error "prohibits anonymous structs|an anonymous struct" }
void foo() { i; }
};
struct B
{
union { static int i; }; // { dg-error "an anonymous union|member of a union" }
void foo() { i; }
};