decl.c (grokdeclarator): Set typedef_decl for all TYPE_DECLs, remove incorrect comment.
authorNathan Sidwell <nathan@codesourcery.com>
Sat, 16 Feb 2002 12:13:41 +0000 (12:13 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Sat, 16 Feb 2002 12:13:41 +0000 (12:13 +0000)
cp:
* decl.c (grokdeclarator): Set typedef_decl for all TYPE_DECLs,
remove incorrect comment. Move #if 0'd code to common path. Use
IMPLICIT_TYPENAME_P. Simplify & reformat ARRAY_TYPE duplication.
testsuite:
* g++.dg/abi/bitfield1.C: New test.
* g++.dg/abi/bitfield2.C: New test.

From-SVN: r49803

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/abi/bitfield1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/abi/bitfield2.C [new file with mode: 0644]

index ac273b146f67edfe7a61af7fd1f315b1010b5dc7..b8f762830cdd246e450617a1544930a193d3c86d 100644 (file)
@@ -1,3 +1,9 @@
+2002-02-15  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * decl.c (grokdeclarator): Set typedef_decl for all TYPE_DECLs,
+       remove incorrect comment. Move #if 0'd code to common path. Use
+       IMPLICIT_TYPENAME_P. Simplify & reformat ARRAY_TYPE duplication.
+
 2002-02-13  Jason Merrill  <jason@redhat.com>
 
        * decl.c (builtin_function): Set TREE_THIS_VOLATILE on return fns.
@@ -65,7 +71,7 @@
 
        PR c++/109
        * decl.c (grokdeclarator): Allow friend declarations from
-       dependant types.
+       dependent types.
        * decl2.c (handle_class_head): Don't push into template parm contexts.
        * pt.c (push_template_decl_real): Template parm contexts are never
        being defined.
index ecc60836f32fd521ada0dc0effd8c94e771082d2..697120a30916751e8ddb96de8e50262293c61ac8 100644 (file)
@@ -10073,7 +10073,6 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
                }
            }
        }
-      /* C++ aggregate types.  */
       else if (TREE_CODE (id) == TYPE_DECL)
        {
          if (type)
@@ -10083,6 +10082,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
            {
              type = TREE_TYPE (id);
              TREE_VALUE (spec) = type;
+             typedef_decl = id;
            }
          goto found;
        }
@@ -10097,10 +10097,6 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
          else
            {
              type = TREE_TYPE (t);
-#if 0
-             /* See the code below that used this.  */
-             decl_attr = DECL_ATTRIBUTES (id);
-#endif
              typedef_decl = t;
            }
        }
@@ -10111,6 +10107,11 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
     found: ;
     }
 
+#if 0
+  /* See the code below that used this.  */
+  if (typedef_decl)
+    decl_attr = DECL_ATTRIBUTES (typedef_decl);
+#endif
   typedef_type = type;
 
   /* No type at all: default to `int', and set DEFAULTED_INT
@@ -10157,7 +10158,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
       type = integer_type_node;
     }
   
-  if (type && TREE_CODE (type) == TYPENAME_TYPE && TREE_TYPE (type))
+  if (type && IMPLICIT_TYPENAME_P (type))
     {
       /* The implicit typename extension is deprecated and will be
         removed.  Warn about its use now.  */
@@ -11221,16 +11222,13 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
 
   /* Detect the case of an array type of unspecified size
      which came, as such, direct from a typedef name.
-     We must copy the type, so that each identifier gets
-     a distinct type, so that each identifier's size can be
-     controlled separately by its own initializer.  */
+     We must copy the type, so that the array's domain can be
+     individually set by the object's initializer.  */
 
-  if (type != 0 && typedef_type != 0
-      && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0
+  if (type && typedef_type
+      && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
       && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
-    {
-      type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
-    }
+    type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
 
   /* Detect where we're using a typedef of function type to declare a
      function. last_function_parms will not be set, so we must create
index 227fad4d29bb8d4b74fcfa8ca15a802c60b727b0..6da29708d47d7aa16fca7cff84903199be1c568f 100644 (file)
@@ -1,3 +1,8 @@
+2002-02-15  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * g++.dg/abi/bitfield1.C: New test.
+       * g++.dg/abi/bitfield2.C: New test.
+
 2002-02-15  Richard Sandiford  <rsandifo@redhat.com>
 
        * gcc.dg/attr-nest.c: New test.
diff --git a/gcc/testsuite/g++.dg/abi/bitfield1.C b/gcc/testsuite/g++.dg/abi/bitfield1.C
new file mode 100644 (file)
index 0000000..c707c85
--- /dev/null
@@ -0,0 +1,34 @@
+// { dg-do run }
+// { dg-options "-ansi -pedantic-errors -funsigned-bitfields" }
+
+// Copyright (C) 2001 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 15 Dec 2001 <nathan@codesourcery.com>
+
+typedef int Int;
+typedef signed int SInt;
+typedef unsigned int UInt;
+
+struct A
+{
+  SInt bitS : 1;       // signed
+  UInt bitU : 1;       // unsigned
+  Int bit : 1;         // signedness by -f{signed,unsigned}-bitfields
+};
+
+int main ()
+{
+  A a;
+
+  a.bitS = 1;
+  a.bitU = 1;
+  a.bit = 1;
+
+  if (a.bitS != -1)
+    return 1;
+  if (a.bitU != 1)
+    return 2;
+  if (a.bit != 1)
+    return 3;
+
+  return 0;
+}
diff --git a/gcc/testsuite/g++.dg/abi/bitfield2.C b/gcc/testsuite/g++.dg/abi/bitfield2.C
new file mode 100644 (file)
index 0000000..d4d1d58
--- /dev/null
@@ -0,0 +1,34 @@
+// { dg-do run }
+// { dg-options "-ansi -pedantic-errors -fsigned-bitfields" }
+
+// Copyright (C) 2001 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 15 Dec 2001 <nathan@codesourcery.com>
+
+typedef int Int;
+typedef signed int SInt;
+typedef unsigned int UInt;
+
+struct A
+{
+  SInt bitS : 1;       // signed
+  UInt bitU : 1;       // unsigned
+  Int bit : 1;         // signedness by -f{signed,unsigned}-bitfields
+};
+
+int main ()
+{
+  A a;
+
+  a.bitS = 1;
+  a.bitU = 1;
+  a.bit = 1;
+
+  if (a.bitS != -1)
+    return 1;
+  if (a.bitU != 1)
+    return 2;
+  if (a.bit != -1)
+    return 3;
+
+  return 0;
+}