Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asterisk array size should be supported in typeof and _Atomic type specifiers which are part of a parameter declaration #90348

Open
Halalaluyafail3 opened this issue Apr 27, 2024 · 6 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@Halalaluyafail3
Copy link

Clang rejects the following declarations:

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

If the size is * instead of being an expression, the array type is a variable length array type of unspecified size, which can only be used as part of the nested sequence of declarators or abstract declarators for a parameter declaration, not including anything inside an array size expression in one of those declarators; (footnote) such arrays are nonetheless complete types.

(foonote) They can be used only in function declarations that are not definitions (see 6.7.7.4 and 6.9.2).

These types should be accepted since the array type [*] is part of the nested sequence of declarators and abstract declarators for a parameter declaration.

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Apr 27, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 27, 2024

@llvm/issue-subscribers-clang-frontend

Author: None (Halalaluyafail3)

Clang rejects the following declarations: ```c void foo(typeof(int(*)[*])(*)[*]); void bar(_Atomic(int(*)[*])(*)[*]); ``` > If the size is * instead of being an expression, the array type is a variable length array type of unspecified size, which can only be used as part of the nested sequence of declarators or abstract declarators for a parameter declaration, not including anything inside an array size expression in one of those declarators; (footnote) such arrays are nonetheless complete types. > > (foonote) They can be used only in function declarations that are not definitions (see 6.7.7.4 and 6.9.2).

These types should be accepted since the array type [*] is part of the nested sequence of declarators and abstract declarators for a parameter declaration.

@pinskia
Copy link

pinskia commented Apr 27, 2024

GCC bug report on this: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114873 .
Note EDG (via ICC): gives an error on this too:

<source>(2): error: variable length array with unspecified bound is not allowed
  void foo(typeof(int(*)[*])(*)[*]);
                         ^

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

So 3 all reject it for the same reason. Which makes me suspect this is not valid.

Note MSVC does not support [*] syntax so it is hard to test that.

@shafik
Copy link
Collaborator

shafik commented Apr 27, 2024

CC @AaronBallman

@MitalAshok
Copy link
Contributor

This wording changed recently

N3096:

If the size is * instead of being an expression, the array type is a variable length array type of unspecified size, which can only be used in declarations or type names with function prototype scope;

N3149 (maybe?) / N3220

If the size is * instead of being an expression, the array type is a variable length array type of unspecified size, which can only be used as part of the nested sequence of declarators or abstract declarators for a parameter declaration, not including anything inside an array size expression in one of those declarators;

DR#341 seems to ban * to the left of where the omitted identifier would have been (from the definition of "scope"), making these invalid (in the older wording)

N3070 is what prompted the wording change

GB-072
As discussed in N3070, this paragraph leaves it unclear what cases are covered by the function prototype scope restriction on [*] declarators. The intended direction disallowing questionable cases was provided in C99 DR#341.

I don't think it was intentional to allow those two declarations.

@pinskia
Copy link

pinskia commented Apr 29, 2024

DR#341 seems to ban * to the left of where the omitted identifier would have been (from the definition of "scope"), making these invalid (in the older wording)

That what is mentioned in the GCC bug report too https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114873#c4

@uecker
Copy link

uecker commented Jun 18, 2024

I am in favor of allowing it. Conceptually it makes sense to allow it anywhere inside function prototype scope where a size expression is used, because this is what is for: replacing size expressions that could be invalid in a different context with a '*'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

7 participants