aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2007-09-20 23:05:38 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2007-09-20 23:05:38 +0000
commit24f58e749753a97db167a73a59dfe1d32f103686 (patch)
treeeeb3fc84c1a2e18eaf34351b6a02cbd84c8b4688
parentfe046210e2d5fa3ac4c0d0d5d48f6851b1dcbe24 (diff)
downloadgcc-24f58e749753a97db167a73a59dfe1d32f103686.zip
gcc-24f58e749753a97db167a73a59dfe1d32f103686.tar.gz
gcc-24f58e749753a97db167a73a59dfe1d32f103686.tar.bz2
re PR c++/33460 (ICE with static member in anonymous union)
cp/ 2007-09-20 Paolo Carlini <pcarlini@suse.de> PR c++/33460 * semantics.c (finish_id_expression): Use consistently context_for_name_lookup. * decl.c (fixup_anonymous_aggr): Fix error message for anonymous struct (vs union). testsuite/ 2007-09-20 Paolo Carlini <pcarlini@suse.de> PR c++/33460 * g++.dg/ext/anon-struct6.C: New. From-SVN: r128637
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/decl.c10
-rw-r--r--gcc/cp/semantics.c14
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/ext/anon-struct6.C10
5 files changed, 39 insertions, 8 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index efad3f3..c9316c6 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2007-09-20 Paolo Carlini <pcarlini@suse.de>
+
+ PR c++/33460
+ * semantics.c (finish_id_expression): Use consistently
+ context_for_name_lookup.
+ * decl.c (fixup_anonymous_aggr): Fix error message for
+ anonymous struct (vs union).
+
2007-09-19 Jason Merrill <jason@redhat.com>
PR c++/7586
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 271b8e6..c589a4b 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -3704,8 +3704,14 @@ fixup_anonymous_aggr (tree t)
/* ISO C++ 9.5.3. Anonymous unions may not have function members. */
if (TYPE_METHODS (t))
- error ("%Jan anonymous union cannot have function members",
- TYPE_MAIN_DECL (t));
+ {
+ tree decl = TYPE_MAIN_DECL (t);
+
+ if (TREE_CODE (t) != UNION_TYPE)
+ error ("%Jan anonymous struct cannot have function members", decl);
+ else
+ error ("%Jan anonymous union cannot have function members", decl);
+ }
/* Anonymous aggregates cannot have fields with ctors, dtors or complex
assignment operators (because they cannot have these methods themselves).
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index b164102..b770269 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2926,13 +2926,15 @@ finish_id_expression (tree id_expression,
else
{
if (DECL_P (decl) && DECL_NONLOCAL (decl)
- && DECL_CLASS_SCOPE_P (decl)
- && context_for_name_lookup (decl) != current_class_type)
+ && DECL_CLASS_SCOPE_P (decl))
{
- tree path;
-
- path = currently_open_derived_class (DECL_CONTEXT (decl));
- perform_or_defer_access_check (TYPE_BINFO (path), decl, decl);
+ tree context = context_for_name_lookup (decl);
+ if (context != current_class_type)
+ {
+ tree path = currently_open_derived_class (context);
+ perform_or_defer_access_check (TYPE_BINFO (path),
+ decl, decl);
+ }
}
decl = convert_from_reference (decl);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a11d20b..3c6c9c8 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2007-09-20 Paolo Carlini <pcarlini@suse.de>
+
+ PR c++/33460
+ * g++.dg/ext/anon-struct6.C: New.
+
2007-09-21 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR libfortran/23272
diff --git a/gcc/testsuite/g++.dg/ext/anon-struct6.C b/gcc/testsuite/g++.dg/ext/anon-struct6.C
new file mode 100644
index 0000000..11a7bbd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/anon-struct6.C
@@ -0,0 +1,10 @@
+// PR c++/33460
+
+struct A
+{
+ struct
+ { // { dg-error "anonymous struct cannot have function members" }
+ struct { static int i; }; // { dg-error "prohibits anonymous structs|non-static data members" }
+ void foo() { i; }
+ }; // { dg-error "prohibits anonymous structs" }
+};