OSDN Git Service

PR c++/46862
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 23 Aug 2011 13:20:04 +0000 (13:20 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 23 Aug 2011 13:20:04 +0000 (13:20 +0000)
* class.c (finish_struct_1): If TYPE_TRANSPARENT_AGGR is set on a type
which doesn't have any fields, clear it and diagnose.

* g++.dg/dfp/nofields.C: New test.

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

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

index f0c0193..b9e83d4 100644 (file)
@@ -1,3 +1,9 @@
+2011-08-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/46862
+       * class.c (finish_struct_1): If TYPE_TRANSPARENT_AGGR is set on a type
+       which doesn't have any fields, clear it and diagnose.
+
 2011-08-18  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
            Marc Glisse  <marc.glisse@normalesup.org>
 
index fd0f011..6ebe758 100644 (file)
@@ -1,6 +1,6 @@
 /* Functions related to building classes and their related objects.
    Copyright (C) 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
    Contributed by Michael Tiemann (tiemann@cygnus.com)
 
@@ -5794,6 +5794,12 @@ 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)
+    {
+      error ("type transparent class %qT does not have any fields", t);
+      TYPE_TRANSPARENT_AGGR (t) = 0;
+    }
 }
 
 /* When T was built up, the member declarations were added in reverse
index fa80622..6d413f3 100644 (file)
@@ -1,3 +1,8 @@
+2011-08-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/46862
+       * g++.dg/dfp/nofields.C: New test.
+
 2011-08-23  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/31600
diff --git a/gcc/testsuite/g++.dg/dfp/nofields.C b/gcc/testsuite/g++.dg/dfp/nofields.C
new file mode 100644 (file)
index 0000000..7234672
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/46862
+// { dg-do compile }
+
+namespace std
+{
+  namespace decimal
+  {
+    class decimal32 { };       // { dg-error "does not have any fields" }
+    class decimal64 { };       // { dg-error "does not have any fields" }
+    class decimal128 { };      // { dg-error "does not have any fields" }
+  }
+}
+
+void
+foo (std::decimal::decimal32 x,
+     std::decimal::decimal64 y,
+     std::decimal::decimal128 z)
+{
+}