summaryrefslogtreecommitdiffstats
path: root/gcc/c-typeck.c
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2009-06-17 13:21:23 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2009-06-17 13:21:23 +0000
commit019c559b7e7214b8016a97cf19168a26b828520a (patch)
treea18365a2a12b66e43938e6451b9ef906434cd866 /gcc/c-typeck.c
parentcf917515dbfbb248a4c828e222714fd7baceafce (diff)
downloadppe42-gcc-019c559b7e7214b8016a97cf19168a26b828520a.tar.gz
ppe42-gcc-019c559b7e7214b8016a97cf19168a26b828520a.zip
./:
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@148611 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-typeck.c')
-rw-r--r--gcc/c-typeck.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 07d51a4d5d8..0a40a888d53 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -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;
}
OpenPOWER on IntegriCloud