public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/114873] New: Incorrect warning generated for [*] array when in atomic or typeof type specifier for a parameter declaration
@ 2024-04-27 20:32 luigighiron at gmail dot com
  2024-04-27 20:37 ` [Bug c/114873] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: luigighiron at gmail dot com @ 2024-04-27 20:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114873
           Summary: Incorrect warning generated for [*] array when in
                    atomic or typeof type specifier for a parameter
                    declaration
           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 generates warnings for [*] arrays when in an atomic or type specifier even
if it is part of a parameter declaration for example:

void foo(typeof(int(*)[*])(*)[*]);
void bar(_Atomic(int(*)[*])(*)[*]);

These generate warnings (saying that '[*]' not in a declaration) when they
should be fine. They should be equivalent to:

void foo(int(*(*)[*])[*]);
void bar(int(*_Atomic(*)[*])[*]);

Which generate no warnings.

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

* [Bug c/114873] Incorrect warning generated for [*] array when in atomic or typeof type specifier for a parameter declaration
  2024-04-27 20:32 [Bug c/114873] New: Incorrect warning generated for [*] array when in atomic or typeof type specifier for a parameter declaration luigighiron at gmail dot com
@ 2024-04-27 20:37 ` pinskia at gcc dot gnu.org
  2024-04-27 20:38 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-27 20:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
clang errors out:
<source>:3:24: error: star modifier used outside of function prototype
    3 | void bar(_Atomic(int(*)[*])(*)[*]);
      |                        ^
<source>:3:30: error: a type specifier is required for all declarations
    3 | void bar(_Atomic(int(*)[*])(*)[*]);
      |                              ^

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

* [Bug c/114873] Incorrect warning generated for [*] array when in atomic or typeof type specifier for a parameter declaration
  2024-04-27 20:32 [Bug c/114873] New: Incorrect warning generated for [*] array when in atomic or typeof type specifier for a parameter declaration luigighiron at gmail dot com
  2024-04-27 20:37 ` [Bug c/114873] " pinskia at gcc dot gnu.org
@ 2024-04-27 20:38 ` pinskia at gcc dot gnu.org
  2024-04-27 20:48 ` luigighiron at gmail dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-27 20:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So does ICC (EDG):

<source>(3): error: variable length array with unspecified bound is not allowed
  void bar(_Atomic(int(*)[*])(*)[*]);
                          ^

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

* [Bug c/114873] Incorrect warning generated for [*] array when in atomic or typeof type specifier for a parameter declaration
  2024-04-27 20:32 [Bug c/114873] New: Incorrect warning generated for [*] array when in atomic or typeof type specifier for a parameter declaration luigighiron at gmail dot com
  2024-04-27 20:37 ` [Bug c/114873] " pinskia at gcc dot gnu.org
  2024-04-27 20:38 ` pinskia at gcc dot gnu.org
@ 2024-04-27 20:48 ` luigighiron at gmail dot com
  2024-04-29 21:30 ` jsm28 at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: luigighiron at gmail dot com @ 2024-04-27 20:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Halalaluyafail3 <luigighiron at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> clang errors out:
> <source>:3:24: error: star modifier used outside of function prototype
>     3 | void bar(_Atomic(int(*)[*])(*)[*]);
>       |                        ^
> <source>:3:30: error: a type specifier is required for all declarations
>     3 | void bar(_Atomic(int(*)[*])(*)[*]);
>       |                              ^

I made a bug report for Clang earlier today about this:
https://github.com/llvm/llvm-project/issues/90348.

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

* [Bug c/114873] Incorrect warning generated for [*] array when in atomic or typeof type specifier for a parameter declaration
  2024-04-27 20:32 [Bug c/114873] New: Incorrect warning generated for [*] array when in atomic or typeof type specifier for a parameter declaration luigighiron at gmail dot com
                   ` (2 preceding siblings ...)
  2024-04-27 20:48 ` luigighiron at gmail dot com
@ 2024-04-29 21:30 ` jsm28 at gcc dot gnu.org
  2024-04-30  1:45 ` luigighiron at gmail dot com
  2024-05-02  5:20 ` muecker at gwdg dot de
  5 siblings, 0 replies; 7+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2024-04-29 21:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Joseph S. Myers <jsm28 at gcc dot gnu.org> ---
These are not meant to be valid C (although the relevant requirement isn't a
Constraint, so a diagnostic isn't required); see the discussion in DR#341.

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

* [Bug c/114873] Incorrect warning generated for [*] array when in atomic or typeof type specifier for a parameter declaration
  2024-04-27 20:32 [Bug c/114873] New: Incorrect warning generated for [*] array when in atomic or typeof type specifier for a parameter declaration luigighiron at gmail dot com
                   ` (3 preceding siblings ...)
  2024-04-29 21:30 ` jsm28 at gcc dot gnu.org
@ 2024-04-30  1:45 ` luigighiron at gmail dot com
  2024-05-02  5:20 ` muecker at gwdg dot de
  5 siblings, 0 replies; 7+ messages in thread
From: luigighiron at gmail dot com @ 2024-04-30  1:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Halalaluyafail3 <luigighiron at gmail dot com> ---
(In reply to Joseph S. Myers from comment #4)
> These are not meant to be valid C (although the relevant requirement isn't a
> Constraint, so a diagnostic isn't required); see the discussion in DR#341.

I thought these declarations were supposed to be valid since there doesn't seem
to be anything forbidding them (unless I misunderstood the text "part of the
nested sequence of declarators or abstract declarators for a parameter
declaration") and they seemed to make sense to me. I did see DR#341 before
making this bug report, and I assumed that it was specifically referring to the
case of [*] in array sizes. Thanks for making the intent clear.

I have recently thought about this again and realized that there may be an
alternative way of doing this:

void foo(typeof(int(*)[(0,0)])(*)[*]);
void bar(_Atomic(int(*)[(0,0)])(*)[*]);

It looks correct as (0,0) is not an integer constant expression and the array
type isn't [*]. GCC and Clang seem to accept this without complaint as well
(haven't tested other compilers). However the current wording says:

> If the size is an expression that is not an integer constant expression:
> if it occurs in a declaration at function prototype scope, it is treated
> as if it were replaced by *; otherwise, each time it is evaluated it shall
> have a value greater than zero.
Section 6.7.7.3 "Array declarators" Paragraph 5 N3220

This wording seems to say that the expression (0,0) would be replaced by *
which would make the program invalid? Or perhaps it means that the type gets
adjusted in the parameter declaration itself so that this is valid. The wording
doesn't seem very clear here, though if it was the former approach then the
following declarations would be invalid:

//the type names in typeof and sizeof have function prototype scope
void baz(size_t x,typeof(int[x])*y);
void qux(size_t x,int(*y)[sizeof(char[x])]);

Which seems unintended. I think this text should be updated to state how *
replacement happens in cases like these. It also isn't clear what would happen
in a declaration like the following:

int a=1;
typedef int b[a];//VLA outside of function prototype scope
void(*c)(b*);//then used in function prototype scope

This would depend upon whether 'it' refers to where the size expression is, or
to where the type is used and then gets adjusted.

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

* [Bug c/114873] Incorrect warning generated for [*] array when in atomic or typeof type specifier for a parameter declaration
  2024-04-27 20:32 [Bug c/114873] New: Incorrect warning generated for [*] array when in atomic or typeof type specifier for a parameter declaration luigighiron at gmail dot com
                   ` (4 preceding siblings ...)
  2024-04-30  1:45 ` luigighiron at gmail dot com
@ 2024-05-02  5:20 ` muecker at gwdg dot de
  5 siblings, 0 replies; 7+ messages in thread
From: muecker at gwdg dot de @ 2024-05-02  5:20 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Uecker <muecker at gwdg dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |muecker at gwdg dot de

--- Comment #6 from Martin Uecker <muecker at gwdg dot de> ---

Supporting this seems better than forcing the user to work around by providing
an incorrect size such as (0, 0).

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

end of thread, other threads:[~2024-05-02  5:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-27 20:32 [Bug c/114873] New: Incorrect warning generated for [*] array when in atomic or typeof type specifier for a parameter declaration luigighiron at gmail dot com
2024-04-27 20:37 ` [Bug c/114873] " pinskia at gcc dot gnu.org
2024-04-27 20:38 ` pinskia at gcc dot gnu.org
2024-04-27 20:48 ` luigighiron at gmail dot com
2024-04-29 21:30 ` jsm28 at gcc dot gnu.org
2024-04-30  1:45 ` luigighiron at gmail dot com
2024-05-02  5:20 ` muecker at gwdg dot de

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).