When trying to compile the following code, I see two bugs in an error mesage:
struct T {
int k;
int l;
};
struct S {
int i;
struct T t;
};
struct T x = {.l = 43, .k = 42, };
void f(void)
{
struct S l = { 1, .t = x, .t.l = 41, }; // Error on this line
ASSERT (l.t.k == 41);
ASSERT (l.t.k == 42);
}
The message is
-:0: error 69: struct/union/array '': initialization needs curly braces
1) The file name and line number are missing (apparently the error is triggered by the declaration inside f, so it should refer to that line.
2) There should be no error here. I understand that SDCC requires curly braces in some places where they are optional in the standard. But in this case, there never should be curly braces.
Bugs: #3121
Bugs: #3408
Feature Requests: #562
Feature Requests: #797
Regarding point 2, i.e. "There should be no error here":
Isn't that more or less documented in section 3.1.1 of the manual?
It only says "initialization of structure arrays must be fully braced", but I believe that the problem occurs with all combinations of arrays, structs and unions.
I tried to find a solution a year or two ago, but both approaches that I tried turned out to be deadends.
I think that expanding the initializer list as early as possible, i.e right when they are being parsed, is the most realistic approach.
But that "fully braced" can only mean that SDCC does not allow omitting braces, even where the standard does allow omitting them.
In this case, there are omitted braces. To me that initalizer looks "fully braced".
Last edit: Philipp Klaus Krause 2020-09-30
Now that I look at it, again, yes, that should work.
One potential problem that comes to mind is the struct assignment
.t = x.Maybe older versions of SDCC would simply have thrown a different error and the special case of struct assignments in initializer lists slipped through, ever since.
Over at [bugs:#3121], I posted a patch for initalizing struct/union.
Unfortunately, it apparently causes a regression here: This code is now accepted, but the
.t.l = 41is ignored (with a warning, but that doesn't feel good enough).Related
Bugs: #3121
Last edit: Philipp Klaus Krause 2024-05-16
Is this same bug? Not-first element of the union is not initialized, reporting a warning. Only for const.