re PR c++/20175 (Warnings are issued when initializing struct members with "strings")

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: r95512
This commit is contained in:
Jakub Jelinek 2005-02-24 22:21:28 +01:00 committed by Jakub Jelinek
parent a0d2281e2d
commit 6ecfe13b3e
4 changed files with 30 additions and 1 deletions

View 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-23 Mark Mitchell <mark@codesourcery.com>
PR c++/19878

View File

@ -4176,6 +4176,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
@ -4239,6 +4240,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))))
@ -4253,6 +4255,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
{
@ -4359,7 +4362,7 @@ reshape_init (tree type, tree *initp)
{
if (brace_enclosed_p)
error ("too many initializers for %qT", type);
else if (warn_missing_braces)
else if (warn_missing_braces && !string_init_p)
warning ("missing braces around initializer");
}

View 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-23 Mark Mitchell <mark@codesourcery.com>
PR c++/19878

View File

@ -0,0 +1,15 @@
// PR c++/20175
// { dg-options "-Wmissing-braces" }
int a[2][2] = { 0, 1, 2, 3 }; // { dg-warning "missing braces" }
int b[2][2] = { { 0, 1 }, { 2, 3 } };
int c[2][2] = { { { 0 }, 1 }, { 2, 3 } }; // { dg-error "brace-enclosed" }
struct S { char s[6]; int i; };
S d = { "hello", 1 };
S e = { { "hello" }, 1 };
S f = { { { "hello" } }, 1 }; // { dg-error "brace-enclosed" }
S g = { 'h', 'e', 'l', 'l', 'o', '\0', 1 }; // { dg-warning "missing braces" }
struct T { wchar_t s[6]; int i; };
T i = { L"hello", 1 };
T j = { { L"hello" }, 1 };
T k = { { { L"hello" } }, 1 }; // { dg-error "brace-enclosed" }
T l = { L'h', L'e', L'l', L'l', L'o', L'\0', 1 };// { dg-warning "missing braces" }