]> gcc.gnu.org Git - gcc.git/commit
c-family: char8_t and aliasing in C vs C++ [PR111884]
authorMarek Polacek <polacek@redhat.com>
Thu, 19 Oct 2023 20:32:10 +0000 (16:32 -0400)
committerMarek Polacek <polacek@redhat.com>
Fri, 20 Oct 2023 19:32:53 +0000 (15:32 -0400)
commit281699fbff6262766674ab13087d37db751cd40a
tree10f1a33e86ffeaec494812e4f3c03e7195494869
parenta663fe63889db486d577b20aff0730034400bfe9
c-family: char8_t and aliasing in C vs C++ [PR111884]

In the PR, Joseph says that in C char8_t is not a distinct type.  So
we should behave as if it can alias anything, like ordinary char.
In C, unsigned_char_type_node == char8_type_node, so with this patch
we return 0 instead of -1.  And the following comment says:

  /* The C standard guarantees that any object may be accessed via an
     lvalue that has narrow character type (except char8_t).  */
  if (t == char_type_node
      || t == signed_char_type_node
      || t == unsigned_char_type_node)
    return 0;

Which appears to be wrong, so I'm adjusting that as well.

PR c/111884

gcc/c-family/ChangeLog:

* c-common.cc (c_common_get_alias_set): Return -1 for char8_t only
in C++.

gcc/testsuite/ChangeLog:

* c-c++-common/alias-1.c: New test.
gcc/c-family/c-common.cc
gcc/testsuite/c-c++-common/alias-1.c [new file with mode: 0644]
This page took 0.059115 seconds and 5 git commands to generate.