]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cp/
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 20 Sep 2007 23:05:38 +0000 (23:05 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 20 Sep 2007 23:05:38 +0000 (23:05 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@128637 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/anon-struct6.C [new file with mode: 0644]

index efad3f3e59ae9b084e3ced2e43200db565797ec3..c9316c695fc129910d2062c5dfa2f6b92d73c2dc 100644 (file)
@@ -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
index 271b8e6885f6c3607f7bd6c438e6e3f2b7b5c95b..c589a4bf5cdbd813f90f58ca9a6f5233d855e0c4 100644 (file)
@@ -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).
index b1641023bd798eae3ce7bf0bb282b86c66689601..b770269100d230b4e18a89ed2d4831f4ff37244f 100644 (file)
@@ -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);
index a11d20b96f08995f914a48ffb68faa5d2247d9ff..3c6c9c82a8a2bf0083b477e8111ffefcfbeb0b5a 100644 (file)
@@ -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 (file)
index 0000000..11a7bbd
--- /dev/null
@@ -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" }
+};