@@ -1407,6 +1407,10 @@ Wunsuffixed-float-constants
C ObjC Var(warn_unsuffixed_float_constants) Warning
Warn about unsuffixed float constants.
+Wunterminated-string-initialization
+C ObjC Var(warn_unterminated_string_initialization) Warning LangEnabledBy(C ObjC,Wextra || Wc++-compat)
+Warn about character arrays initialized as unterminated character sequences by a string literal.
+
Wunused
C ObjC C++ ObjC++ LangEnabledBy(C ObjC C++ ObjC++,Wall)
; documented in common.opt
@@ -8399,11 +8399,11 @@ digest_init (location_t init_loc, tree type, tree init, tree origtype,
pedwarn_init (init_loc, 0,
("initializer-string for array of %qT "
"is too long"), typ1);
- else if (warn_cxx_compat
+ else if (warn_unterminated_string_initialization
&& compare_tree_int (TYPE_SIZE_UNIT (type), len) < 0)
- warning_at (init_loc, OPT_Wc___compat,
+ warning_at (init_loc, OPT_Wunterminated_string_initialization,
("initializer-string for array of %qT "
- "is too long for C++"), typ1);
+ "is too long"), typ1);
if (compare_tree_int (TYPE_SIZE_UNIT (type), len) < 0)
{
unsigned HOST_WIDE_INT size
new file mode 100644
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-Wunterminated-string-initialization" } */
+
+char a1[] = "a";
+char a2[1] = "a"; /* { dg-warning "initializer-string for array of 'char' is too long" } */
+char a3[2] = "a";