Fix Issue #22790: Allow static array parameters in ImportC#22800
Fix Issue #22790: Allow static array parameters in ImportC#22800oCHIKIo wants to merge 2 commits intodlang:masterfrom
Conversation
|
Thanks for your pull request and interest in making D better, @oCHIKIo! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.
|
24e2026 to
a8c8d12
Compare
a8c8d12 to
2e113d6
Compare
|
@kinke I ve added the _Static_assert to verify the array decays to a pointer. Let me know if everything looks good to merge! |
Further, are you following the other semantics as per C11 spec? |
|
@ibuclaw yes, the array decays to a pointer perfectly. ImportC already adjusts array parameters to pointers automatically, and I included a |
|
I see. 6.7.6.2-1
then
Both the above should be enforced with an error if one does not exist yet. int fn(int arr[static 1][2]); // Valid
int fn(int arr[1][static 2]); // Error, static in non-parameter array declarator
int var[static 1][2]; // Error, static in non-parameter array declarator6.7.6.3-7
The following are all compatible function prototype declarators. int fn(int (* restrict a)[5]);
int fn(int a[restrict][5]);
int fn(int a[restrict 3][5]);
int fn(int a[restrict static 3][5]);
int gn()
{
int b[3][5];
return fn(b); // OK, no conflicts.
} |
Bounds checks are not part of the spec. So I'd consider it something for an static analyzer to deal with. |
|
Likewise, do expressions work with this? void f1 (int[static 1 + 1]);
void f2 (int a, int x[static sizeof a]);
// IIRC, we don't support VLA's yet.
void f3 (int a, int x[static a]); |
|
Finally, maybe a test for each i.e: This should compile. void f1 (int a[static 2])
{
int **b = &a;
int *const *c = &a;
}
void f2 (a)
int a[static 2];
{
int **b = &a;
int *const *c = &a;
}
void f3 (int a[static const 2])
{
int **b = &a;
int *const *c = &a;
}
void f4 (a)
int a[static const 2];
{
int **b = &a;
int *const *c = &a;
} |
|
@ibuclaw I ran those tests and it looks like DMD already handles the restrictions perfectly the invalid placements like for expressions, stuff like for the qualifiers, standard prototypes like want me to add the working examples to the test file? |
fixes #22790
by removing the hardcoded error in cparse.d that explicitly rejected the static keyword inside array parameters. since the compiler's underlying parser already handles the array type structure correctly, simply lifting this restriction allows the C99-compliant behavior to work naturally. I also updated the failcstuff1.c test suite so it no longer expects the compiler to fail when it encounters this syntax.