OSDN Git Service

PR c++/50207
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 30 Aug 2011 04:30:42 +0000 (04:30 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 30 Aug 2011 04:30:42 +0000 (04:30 +0000)
* class.c (finish_struct_1): Complain if the first field is
artificial.

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

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/dfp/base.C [new file with mode: 0644]

index d42d89a..17065de 100644 (file)
@@ -1,3 +1,10 @@
+2011-08-29  Jakub Jelinek  <jakub@redhat.com>
+           Jason Merrill  <jason@redhat.com>
+
+       PR c++/50207
+       * class.c (finish_struct_1): Complain if the first field is
+       artificial.
+
 2011-08-29  Jason Merrill  <jason@redhat.com>
 
        PR c++/50209
index 6ebe758..2a4bc77 100644 (file)
@@ -5795,10 +5795,25 @@ finish_struct_1 (tree t)
   /* Finish debugging output for this type.  */
   rest_of_type_compilation (t, ! LOCAL_CLASS_P (t));
 
-  if (TYPE_TRANSPARENT_AGGR (t) && first_field (t) == NULL_TREE)
+  if (TYPE_TRANSPARENT_AGGR (t))
     {
-      error ("type transparent class %qT does not have any fields", t);
-      TYPE_TRANSPARENT_AGGR (t) = 0;
+      tree field = first_field (t);
+      if (field == NULL_TREE || error_operand_p (field))
+       {
+         error ("type transparent class %qT does not have any fields", t);
+         TYPE_TRANSPARENT_AGGR (t) = 0;
+       }
+      else if (DECL_ARTIFICIAL (field))
+       {
+         if (DECL_FIELD_IS_BASE (field))
+           error ("type transparent class %qT has base classes", t);
+         else
+           {
+             gcc_checking_assert (DECL_VIRTUAL_P (field));
+             error ("type transparent class %qT has virtual functions", t);
+           }
+         TYPE_TRANSPARENT_AGGR (t) = 0;
+       }
     }
 }
 
index c5208af..c503b69 100644 (file)
@@ -1,3 +1,8 @@
+2011-08-29  Jakub Jelinek  <jakub@redhat.com>
+           Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/dfp/base.C: New test.
+
 2011-08-29  Jason Merrill  <jason@redhat.com>
 
        Core DR 994
diff --git a/gcc/testsuite/g++.dg/dfp/base.C b/gcc/testsuite/g++.dg/dfp/base.C
new file mode 100644 (file)
index 0000000..3e5dc50
--- /dev/null
@@ -0,0 +1,23 @@
+// PR c++/50207
+// { dg-do compile }
+
+namespace std
+{
+  namespace decimal
+  {
+    template <class _Fmt> struct _FmtTraits;
+    class decimal32;
+    template <> struct _FmtTraits <decimal32>
+    {
+      static const long _NumBytes = 4UL;
+    };
+    template <class _Tr> class _DecBase
+    {
+      unsigned char _Bytes[_Tr::_NumBytes];
+    };
+    class decimal32 : public _DecBase <_FmtTraits <decimal32> >        // { dg-error "has base" }
+    {
+      decimal32 () { }
+    };
+  }
+}