]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: set TYPE_STRING_FLAG for char8_t
authorJason Merrill <jason@redhat.com>
Wed, 24 Aug 2022 20:31:11 +0000 (16:31 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 1 Sep 2022 12:33:46 +0000 (08:33 -0400)
While looking at the DWARF handling of char8_t I wondered why we weren't
setting TREE_STRING_FLAG on it.  I hoped that setting that flag would be an
easy fix for PR102958, but it doesn't seem to be sufficicent.  But it still
seems correct.

I also tried setting the flag on char16_t and char32_t, but that broke
because braced_list_to_string assumes char-sized elements.  Since we don't
set the flag on wchar_t, I abandoned that idea.

gcc/c-family/ChangeLog:

* c-common.cc (c_common_nodes_and_builtins): Set TREE_STRING_FLAG on
char8_t.
(braced_list_to_string): Check for char-sized elements.

gcc/c-family/c-common.cc

index 1eb842e1c7bace7ba33a25c11242fc96ae079665..9746504195b26512160db11e4f87b8110b828919 100644 (file)
@@ -4550,6 +4550,7 @@ c_common_nodes_and_builtins (void)
   if (c_dialect_cxx ())
     {
       char8_type_node = make_unsigned_type (char8_type_size);
+      TYPE_STRING_FLAG (char8_type_node) = true;
 
       if (flag_char8_t)
         record_builtin_type (RID_CHAR8, "char8_t", char8_type_node);
@@ -9345,12 +9346,15 @@ braced_list_to_string (tree type, tree ctor, bool member)
   if (!member && !tree_fits_uhwi_p (typesize))
     return ctor;
 
-  /* If the target char size differes from the host char size, we'd risk
+  /* If the target char size differs from the host char size, we'd risk
      loosing data and getting object sizes wrong by converting to
      host chars.  */
   if (TYPE_PRECISION (char_type_node) != CHAR_BIT)
     return ctor;
 
+  /* STRING_CST doesn't support wide characters.  */
+  gcc_checking_assert (TYPE_PRECISION (TREE_TYPE (type)) == CHAR_BIT);
+
   /* If the array has an explicit bound, use it to constrain the size
      of the string.  If it doesn't, be sure to create a string that's
      as long as implied by the index of the last zero specified via