diff options
author | Jakub Jelinek <jakub@redhat.com> | 2018-11-28 09:50:53 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2018-11-28 09:50:53 +0100 |
commit | 62574f122c7aab5fe06e1b68c659650c17964dc4 (patch) | |
tree | f2dd567f03518922286d256ea88871441e72ba25 /gcc | |
parent | ace83db06c03b138c8b4cf87bf3db61f2d842e60 (diff) | |
download | gcc-62574f122c7aab5fe06e1b68c659650c17964dc4.zip gcc-62574f122c7aab5fe06e1b68c659650c17964dc4.tar.gz gcc-62574f122c7aab5fe06e1b68c659650c17964dc4.tar.bz2 |
re PR c++/87476 (char-array initialized from wide-string)
PR c++/87476
* typeck2.c (digest_init_r): Re-add handing of signed/unsigned char
strings and add it to the initialization of wide array from non-wide
string diagnostics too.
* g++.dg/cpp0x/pr87476-1.C: New test.
* g++.dg/cpp0x/pr87476-2.C: New test.
From-SVN: r266547
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/typeck2.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/pr87476-1.C | 13 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/pr87476-2.C | 23 |
5 files changed, 53 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index fea3cf6..c0f04d5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2018-11-28 Jakub Jelinek <jakub@redhat.com> + + PR c++/87476 + * typeck2.c (digest_init_r): Re-add handing of signed/unsigned char + strings and add it to the initialization of wide array from non-wide + string diagnostics too. + 2018-11-27 Jakub Jelinek <jakub@redhat.com> PR c++/88187 diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index fec1db0..d0b1235 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -1063,7 +1063,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"); @@ -1072,7 +1074,9 @@ digest_init_r (tree type, tree init, int nested, int flags, } else { - 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, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 411a3c8..f205d65 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2018-11-28 Jakub Jelinek <jakub@redhat.com> + PR c++/87476 + * g++.dg/cpp0x/pr87476-1.C: New test. + * g++.dg/cpp0x/pr87476-2.C: New test. + PR c++/88215 * c-c++-common/ubsan/pr88215.c: New test. diff --git a/gcc/testsuite/g++.dg/cpp0x/pr87476-1.C b/gcc/testsuite/g++.dg/cpp0x/pr87476-1.C new file mode 100644 index 0000000..31df51a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr87476-1.C @@ -0,0 +1,13 @@ +// PR c++/87476 +// { dg-do compile { target c++11 } } + +template <int> +struct S { + void operator () () { constexpr unsigned char p[1] {}; } +}; + +void +foo () +{ + S<0>{} (); +} diff --git a/gcc/testsuite/g++.dg/cpp0x/pr87476-2.C b/gcc/testsuite/g++.dg/cpp0x/pr87476-2.C new file mode 100644 index 0000000..fac0ec1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr87476-2.C @@ -0,0 +1,23 @@ +// PR c++/87476 +// { dg-do compile { target c++11 } } + +void f0 () { constexpr char p[] = "11111"; } +void f1 () { constexpr unsigned char p[] = "11111"; } +void f2 () { constexpr signed char p[] = "11111"; } +template <int N> +void f3 () { constexpr char p[] = "11111"; } +template <int N> +void f4 () { constexpr unsigned char p[] = "11111"; } +template <int N> +void f5 () { constexpr signed char p[] = "11111"; } + +void +baz () +{ + f0 (); + f1 (); + f2 (); + f3<0> (); + f4<0> (); + f5<0> (); +} |