aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/decl.c36
-rw-r--r--gcc/cp/typeck2.c4
3 files changed, 46 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index da6703b..e4984bd 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2018-08-13 Martin Sebor <msebor@redhat.com>
+
+ PR tree-optimization/71625
+ * decl.c (check_initializer): Call braced_list_to_string.
+ (eval_check_narrowing): New function.
+ * gcc/cp/typeck2.c (digest_init_r): Accept strings literals
+ as initilizers for all narrow character types.
+
2018-08-13 Marek Polacek <polacek@redhat.com>
P0806R2 - Deprecate implicit capture of this via [=]
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index b021ff6..97f1cfb 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6282,6 +6282,30 @@ build_aggr_init_full_exprs (tree decl, tree init, int flags)
return build_aggr_init (decl, init, flags, tf_warning_or_error);
}
+/* Attempt to determine the constant VALUE of integral type and convert
+ it to TYPE, issuing narrowing warnings/errors as necessary. Return
+ the constant result or null on failure. Callback for
+ braced_list_to_string. */
+
+static tree
+eval_check_narrowing (tree type, tree value)
+{
+ if (tree valtype = TREE_TYPE (value))
+ {
+ if (TREE_CODE (valtype) != INTEGER_TYPE)
+ return NULL_TREE;
+ }
+ else
+ return NULL_TREE;
+
+ value = scalar_constant_value (value);
+ if (!value)
+ return NULL_TREE;
+
+ check_narrowing (type, value, tf_warning_or_error);
+ return value;
+}
+
/* Verify INIT (the initializer for DECL), and record the
initialization in DECL_INITIAL, if appropriate. CLEANUP is as for
grok_reference_init.
@@ -6397,7 +6421,17 @@ check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
}
else
{
- init = reshape_init (type, init, tf_warning_or_error);
+ /* Try to convert a string CONSTRUCTOR into a STRING_CST. */
+ tree valtype = TREE_TYPE (decl);
+ if (TREE_CODE (valtype) == ARRAY_TYPE
+ && TYPE_STRING_FLAG (TREE_TYPE (valtype))
+ && BRACE_ENCLOSED_INITIALIZER_P (init))
+ if (tree str = braced_list_to_string (valtype, init,
+ eval_check_narrowing))
+ init = str;
+
+ if (TREE_CODE (init) != STRING_CST)
+ init = reshape_init (type, init, tf_warning_or_error);
flags |= LOOKUP_NO_NARROWING;
}
}
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 7763d53..72515d9 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -1056,7 +1056,9 @@ digest_init_r (tree type, tree init, int nested, int flags,
if (TYPE_PRECISION (typ1) == BITS_PER_UNIT)
{
- if (char_type != char_type_node)
+ if (char_type != char_type_node
+ && char_type != signed_char_type_node
+ && char_type != unsigned_char_type_node)
{
if (complain & tf_error)
error_at (loc, "char-array initialized from wide string");