===================================================================
@@ -7502,6 +7502,18 @@ cp_build_modify_expr (tree lhs, enum tree_code mod
return error_mark_node;
}
+ /* C++11 8.5/17: "If the destination type is an array of characters,
+ an array of char16_t, an array of char32_t, or an array of wchar_t,
+ and the initializer is a string literal...". */
+ else if (TREE_CODE (newrhs) == STRING_CST
+ && char_type_p (TREE_TYPE (lhstype))
+ && modifycode == INIT_EXPR)
+ {
+ newrhs = digest_init (lhstype, newrhs, complain);
+ if (newrhs == error_mark_node)
+ return error_mark_node;
+ }
+
else if (!same_or_base_type_p (TYPE_MAIN_VARIANT (lhstype),
TYPE_MAIN_VARIANT (TREE_TYPE (newrhs))))
{
===================================================================
@@ -786,7 +786,12 @@ store_init_value (tree decl, tree init, vec<tree,
gcc_assert (TREE_CODE (decl) != RESULT_DECL);
if (TREE_CODE (init) == TREE_LIST
- && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
+ && TREE_CODE (type) == ARRAY_TYPE
+ /* C++11 8.5/17: "If the destination type is an array of characters,
+ an array of char16_t, an array of char32_t, or an array of wchar_t,
+ and the initializer is a string literal...". */
+ && !(char_type_p (TREE_TYPE (type))
+ && TREE_CODE (TREE_VALUE (init)) == STRING_CST))
{
error ("cannot initialize arrays using this syntax");
return NULL_TREE;
===================================================================
@@ -0,0 +1,22 @@
+// PR c++/43453
+
+struct A {
+ char x[4];
+ A() : x("bug") { };
+};
+
+char x [4] ("bug");
+
+struct B {
+ char y[4];
+ B() : y("bu") { };
+};
+
+char y [4] ("bu");
+
+struct C {
+ char z[4];
+ C() : z("bugs") { }; // { dg-error "too long" }
+};
+
+char z [4] ("bugs"); // { dg-error "too long" }