]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-pch.c (get_ident): Don't set size of templ array.
authorIan Lance Taylor <iant@google.com>
Wed, 17 Jun 2009 13:21:23 +0000 (13:21 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Wed, 17 Jun 2009 13:21:23 +0000 (13:21 +0000)
./: * c-pch.c (get_ident): Don't set size of templ array.
(pch_init): Don't set size of partial_pch array.

* c-typeck.c (digest_init): If -Wc++-compat, warn about using a
string constant to intialize an array whose size is the length of
the string.
testsuite/:
* gcc.dg/Wcxx-compat-14.c: New testcase.

From-SVN: r148611

gcc/ChangeLog
gcc/c-pch.c
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wcxx-compat-14.c [new file with mode: 0644]

index c21b72ef7ba8dd1a829897592582d92a0ff2648e..2291ec21836ae5bc7457ec3865268a7bb27f7fe5 100644 (file)
@@ -1,3 +1,12 @@
+2009-06-17  Ian Lance Taylor  <iant@google.com>
+
+       * c-pch.c (get_ident): Don't set size of templ array.
+       (pch_init): Don't set size of partial_pch array.
+
+       * c-typeck.c (digest_init): If -Wc++-compat, warn about using a
+       string constant to intialize an array whose size is the length of
+       the string.
+
 2009-06-17  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/40389
index b4f70506e40b40466da26f7f22b23d345da66849..abdf4ab46772e00505911044b1097f666ded3946 100644 (file)
@@ -1,5 +1,6 @@
 /* Precompiled header implementation for the C languages.
-   Copyright (C) 2000, 2002, 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2002, 2003, 2004, 2005, 2007, 2008, 2009
+   Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -92,7 +93,7 @@ static const char *
 get_ident (void)
 {
   static char result[IDENT_LENGTH];
-  static const char templ[IDENT_LENGTH] = "gpch.013";
+  static const char templ[] = "gpch.013";
   static const char c_language_chars[] = "Co+O";
 
   memcpy (result, templ, IDENT_LENGTH);
@@ -112,7 +113,7 @@ pch_init (void)
   FILE *f;
   struct c_pch_validity v;
   void *target_validity;
-  static const char partial_pch[IDENT_LENGTH] = "gpcWrite";
+  static const char partial_pch[] = "gpcWrite";
 
 #ifdef ASM_COMMENT_START
   if (flag_verbose_asm)
index 07d51a4d5d82b7bb6c8bfe078f44a2f2e0600a0d..0a40a888d5301a7da5a951bbff3a59a0d20d1d63 100644 (file)
@@ -5546,16 +5546,26 @@ digest_init (location_t init_loc, tree type, tree init, tree origtype,
          TREE_TYPE (inside_init) = type;
          if (TYPE_DOMAIN (type) != 0
              && TYPE_SIZE (type) != 0
-             && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
+             && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
+           {
+             unsigned HOST_WIDE_INT len = TREE_STRING_LENGTH (inside_init);
+
              /* Subtract the size of a single (possibly wide) character
                 because it's ok to ignore the terminating null char
                 that is counted in the length of the constant.  */
-             && 0 > compare_tree_int (TYPE_SIZE_UNIT (type),
-                                      TREE_STRING_LENGTH (inside_init)
-                                      - (TYPE_PRECISION (typ1)
-                                         / BITS_PER_UNIT)))
-           pedwarn_init (init_loc, 0, 
-                         "initializer-string for array of chars is too long");
+             if (0 > compare_tree_int (TYPE_SIZE_UNIT (type),
+                                       (len
+                                        - (TYPE_PRECISION (typ1)
+                                           / BITS_PER_UNIT))))
+               pedwarn_init (init_loc, 0,
+                             ("initializer-string for array of chars "
+                              "is too long"));
+             else if (warn_cxx_compat
+                      && 0 > compare_tree_int (TYPE_SIZE_UNIT (type), len))
+               warning_at (init_loc, OPT_Wc___compat,
+                           ("initializer-string for array chars "
+                            "is too long for C++"));
+           }
 
          return inside_init;
        }
index 42ec5145b8ea24cce954f2c9de128ab0b3b6e85e..3e42e51de704602021f44b8b9a9ce036c50968a7 100644 (file)
@@ -1,3 +1,7 @@
+2009-06-17  Ian Lance Taylor  <iant@google.com>
+
+       * gcc.dg/Wcxx-compat-14.c: New testcase.
+
 2009-06-17  Aldy Hernandez  <aldyh@redhat.com>
 
        * gcc.dg/func-ptr-conv-1.c: Update column info.
diff --git a/gcc/testsuite/gcc.dg/Wcxx-compat-14.c b/gcc/testsuite/gcc.dg/Wcxx-compat-14.c
new file mode 100644 (file)
index 0000000..2378371
--- /dev/null
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-Wc++-compat" } */
+
+char a1[] = "a";
+char a2[1] = "a";      /* { dg-warning "C\[+\]\[+\]" } */
+char a3[2] = "a";