]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/20175 (Warnings are issued when initializing struct members with "strings")
authorJakub Jelinek <jakub@redhat.com>
Sun, 27 Feb 2005 18:10:41 +0000 (19:10 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sun, 27 Feb 2005 18:10:41 +0000 (19:10 +0100)
PR c++/20175
* decl.c (reshape_init): Don't warn about missing braces if STRING_CST
initializes a char/wchar_t array.

* g++.dg/warn/Wbraces2.C: New test.

From-SVN: r95626

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog

index d463c0c80f85c91433cdbd688a45f64d30a458e2..003cff3cf844af840e6ff854da1b9c061899584f 100644 (file)
@@ -1,3 +1,9 @@
+2005-02-24  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/20175
+       * decl.c (reshape_init): Don't warn about missing braces if STRING_CST
+       initializes a char/wchar_t array.
+
 2005-02-21  Alexandre Oliva  <aoliva@redhat.com>
 
        PR c++/20028
index e8bcead6f39c6dd0e1462bf2e1d7c09a025c30d9..397b60d56441060d3c368f9825e69d2d52d0a32e 100644 (file)
@@ -4276,6 +4276,7 @@ reshape_init (tree type, tree *initp)
   tree old_init_value;
   tree new_init;
   bool brace_enclosed_p;
+  bool string_init_p;
 
   old_init = *initp;
   old_init_value = (TREE_CODE (*initp) == TREE_LIST
@@ -4340,6 +4341,7 @@ reshape_init (tree type, tree *initp)
       return old_init;
     }
 
+  string_init_p = false;
   if (TREE_CODE (old_init_value) == STRING_CST
       && TREE_CODE (type) == ARRAY_TYPE
       && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
@@ -4354,6 +4356,7 @@ reshape_init (tree type, tree *initp)
       /* Move past the initializer.  */
       *initp = TREE_CHAIN (old_init);
       TREE_CHAIN (old_init) = NULL_TREE;
+      string_init_p = true;
     }
   else
     {
@@ -4448,7 +4451,7 @@ reshape_init (tree type, tree *initp)
     {
       if (brace_enclosed_p)
        error ("too many initializers for `%T'", type);
-      else if (warn_missing_braces)
+      else if (warn_missing_braces && !string_init_p)
        warning ("missing braces around initializer");
     }
 
index fe0f23b6b396fd04d6f182f3b7d87a7fed70b6df..86bf512dcda687ddc8bd589749178df5a5888f9d 100644 (file)
@@ -1,3 +1,8 @@
+2005-02-24  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/20175
+       * g++.dg/warn/Wbraces2.C: New test.
+
 2005-02-21  Alexandre Oliva  <aoliva@redhat.com>
 
        PR c++/20028