[Issue 22652] New: importC: Braceless initializer of nested struct is rejected.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jan 5 01:40:11 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=22652
Issue ID: 22652
Summary: importC: Braceless initializer of nested struct is
rejected.
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: dave287091 at gmail.com
Consider the following C program:
// s.c
struct S1 {
int x, y;
};
struct S2 {
struct S1 s;
};
int printf(const char*, ...);
int main(void){
int x = {1};
struct S1 a = {0}; // ok
struct S2 b = {{0}}; // ok
struct S2 c = {1}; // Error: cannot implicitly convert expression `1` of
type `int` to `S1`
struct S2 c2 = {1, 2}; // Error: cannot implicitly convert expression `1`
of type `int` to `S1`
struct S1 d[2] = {1, 2}; // Error: variable `s.main.d` is not a static and
cannot have static initializer
struct S1 e[] = {3, 4}; // Error: variable `s.main.e` is not a static and
cannot have static initializer
printf("%d,%d\n", b.s.x, b.s.y); // should print 0, 0
printf("%d,%d\n", c.s.x, c.s.y); // should print 1, 0
printf("%d,%d\n", c2.s.x, c2.s.y); // should print 1, 2
printf("%d,%d\n", d[0].x, d[0].y); // should print 1, 2
printf("%d,%d\n", d[1].x, d[1].y); // should print 0, 0
printf("%zu\n", sizeof(e) / sizeof(e[0])); // should print 1
printf("%d,%d\n", e[0].x, e[0].y); // should print 3, 4
return 0;
}
C11 does not require braces. Clauses 20 and 21 of 6.7.9 Initialization address
what should be done.
"variable `s.main.d` is not a static and cannot have static initializer” is
also a weird error message in this case.
--
More information about the Digitalmars-d-bugs
mailing list