public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/112841] New: typeof_unqual is not removing qualifiers from array types
@ 2023-12-04  5:16 luigighiron at gmail dot com
  2023-12-04  6:43 ` [Bug c/112841] typeof_unqual is not removing qualifiers from the element type of " pinskia at gcc dot gnu.org
  2023-12-04  6:51 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: luigighiron at gmail dot com @ 2023-12-04  5:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112841

            Bug ID: 112841
           Summary: typeof_unqual is not removing qualifiers from array
                    types
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: luigighiron at gmail dot com
  Target Milestone: ---

GCC does not remove qualifiers from array types when used with typeof_unqual:

puts(_Generic(
    (typeof_unqual(const int[])*)0,
    int(*)[]:"non-const",
    const int(*)[]:"const"
));

This should print non-const, but GCC prints const.

The latest working draft of the standard includes an example of typeof_unqual
with an array of const:

> EXAMPLE 2 The following program:
> const _Atomic int purr = 0;
> const int meow = 1;
> const char* const animals[] = {
> "aardvark",
> "bluejay",
> "catte",
> };
> typeof_unqual(meow) main (int argc, char* argv[]) {
> typeof_unqual(purr) plain_purr;
> typeof(_Atomic typeof(meow)) atomic_meow;
> typeof(animals) animals_array;
> typeof_unqual(animals) animals2_array;
> return 0;
> }
> is equivalent to this program:
> const _Atomic int purr = 0;
> const int meow = 1;
> const char* const animals[] = {
> "aardvark",
> "bluejay",
> "catte",
> };
> int main (int argc, char* argv[]) {
> int plain_purr;
> const _Atomic int atomic_meow;
> const char* const animals_array[3];
> const char* animals2_array[3];
> return 0;
> }
Section 6.7.2.5 "Typeof specifiers" Paragraph 7, from N3096

Here, GCC does not not remove the const on the array type for animals2_array in
the first part of the example.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/112841] typeof_unqual is not removing qualifiers from the element type of array types
  2023-12-04  5:16 [Bug c/112841] New: typeof_unqual is not removing qualifiers from array types luigighiron at gmail dot com
@ 2023-12-04  6:43 ` pinskia at gcc dot gnu.org
  2023-12-04  6:51 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-04  6:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112841

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
            Summary|typeof_unqual is not        |typeof_unqual is not
                   |removing qualifiers from    |removing qualifiers from
                   |array types                 |the element type of array
                   |                            |types
   Last reconfirmed|                            |2023-12-04

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Hmm, 6.7.3/10
"If the specification of an array type includes any type qualifiers, both the
array and the element type are so-qualified." and the note 166 notes that this
can happen with typedefs ...

But then typeof_unqual only mentions the about the type qualifer of the array
and not the element type but the example is showing it means the element type
of the array should be unqualified too ...

I am suspecting if we are pedantic about the language used, this would be a
defect in the standard where the typeof_unqual does not mention the `element
type` when it should as the example intends it as such.


Note GCC does not try to remove qualifiers from the element type because of
this quirk in the language of the standard dealing with array types ...

Confirmed at least GCC is not following the example in the standard ...

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/112841] typeof_unqual is not removing qualifiers from the element type of array types
  2023-12-04  5:16 [Bug c/112841] New: typeof_unqual is not removing qualifiers from array types luigighiron at gmail dot com
  2023-12-04  6:43 ` [Bug c/112841] typeof_unqual is not removing qualifiers from the element type of " pinskia at gcc dot gnu.org
@ 2023-12-04  6:51 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-04  6:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112841

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note clang also gets this "wrong".

You can see that from:
```
const char* const animals[] = {
"aardvark",
"bluejay",
 "catte",
};
int main (int argc, char* argv[]) {
 const char* animals2_array1[3];
 typeof_unqual(animals) animals2_array;
 animals2_array1[0] = 0;
 animals2_array[0] = 0;
 return 0;
}
```

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-04  6:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-04  5:16 [Bug c/112841] New: typeof_unqual is not removing qualifiers from array types luigighiron at gmail dot com
2023-12-04  6:43 ` [Bug c/112841] typeof_unqual is not removing qualifiers from the element type of " pinskia at gcc dot gnu.org
2023-12-04  6:51 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).