(finish_struct): Warn if field with enumeral type is narrower than
authorRichard Kenner <kenner@gcc.gnu.org>
Mon, 1 Jan 1996 14:30:37 +0000 (09:30 -0500)
committerRichard Kenner <kenner@gcc.gnu.org>
Mon, 1 Jan 1996 14:30:37 +0000 (09:30 -0500)
values of that type.

From-SVN: r10928

gcc/c-decl.c

index 51b9636..121424d 100644 (file)
@@ -1,5 +1,5 @@
 /* Process declarations and variables for C compiler.
-   Copyright (C) 1988, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+   Copyright (C) 1988, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -5569,6 +5569,13 @@ finish_struct (t, fieldlist, attributes)
        {
          register int width = TREE_INT_CST_LOW (DECL_INITIAL (x));
 
+         if (TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
+             && (width < min_precision (TYPE_MIN_VALUE (TREE_TYPE (x)),
+                                        TREE_UNSIGNED (TREE_TYPE (x)))
+                 || width < min_precision (TYPE_MAX_VALUE (TREE_TYPE (x)),
+                                           TREE_UNSIGNED (TREE_TYPE (x)))))
+           warning_with_decl (x, "`%s' is narrower than values of its type");
+
          DECL_FIELD_SIZE (x) = width;
          DECL_BIT_FIELD (x) = DECL_C_BIT_FIELD (x) = 1;
          DECL_INITIAL (x) = NULL;