[Issue 22103] New: importC: Parser accepts wrong syntax for array declarators
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Jul 6 00:01:36 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22103
Issue ID: 22103
Summary: importC: Parser accepts wrong syntax for array
declarators
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: critical
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: ibuclaw at gdcproject.org
Syntax in 6.7.6 is:
---
direct-declarator [ type-qualifier-list(opt) assignment-expression(opt) ]
direct-declarator [ static type-qualifier-list(opt) assignment-expression ]
direct-declarator [ type-qualifier-list static assignment-expression ]
direct-declarator [ type-qualifier-list(opt) * ]
---
But CParser instead parses C code as if it is instead:
---
direct-declarator [ assignment-expression(opt) ] type-qualifier-list(opt)
direct-declarator [ static assignment-expression(opt) ]
type-qualifier-list(opt)
direct-declarator [ * assignment-expression(opt) ] type-qualifier-list(opt)
---
E.g: This code is wrong, but dmd compiles it as valid.
---
void test(int arr[4] const, int val);
int main()
{
int array[4] const;
test(array, 4);
return 0;
}
---
Conversely, this code is correct, but dmd rejects it.
---
void test(int arr[restrict 4], int val);
int main()
{
int array[4];
test(array, 4);
return 0;
}
---
Implementation detail (C11 6.7.6.2-1): The optional type-qualifiers and the
keyword `static` shall appear only in a declaration of a function parameter
with an array type, and then only in the outermost array type derivation.
Meaning , this code should be rejected:
---
void badparam1(int arr[4][restrict]);
void badparam2(int arr[4][static 2]);
int var[static 4];
typedef int carray[const];
---
etc...
--
More information about the Digitalmars-d-bugs
mailing list