Message ID | 20240917070854.56010-1-michael.adler@siemens.com |
---|---|
State | Changes Requested |
Delegated to: | Stefano Babic |
Headers | show |
Series | style: label followed by a declaration is a C23 extension | expand |
On 17.09.24 09:08, 'Michael Adler' via swupdate wrote: > Clang refuses to compile code with a label followed by a declaration, as > it is against the C standard specifications. This commit applies a > simple fix to ensure compatibility with the C standard. > Well, then we can simply move "int fd" before the "switch (c)", then it is C99. It seems we should add a test case in CI with clang, I always use gcc and I do not get these errors (and yes, I was aware of this, but as gcc didn't complain, it was ok to me).. Best regards, Stefano > Reported-by: Christian Storm <christian.storm@siemens.com> > Signed-off-by: Michael Adler <michael.adler@siemens.com> > Signed-off-by: Christian Storm <christian.storm@siemens.com> > --- > core/swupdate.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/core/swupdate.c b/core/swupdate.c > index dc818599..d0633c69 100644 > --- a/core/swupdate.c > +++ b/core/swupdate.c > @@ -538,7 +538,7 @@ int main(int argc, char **argv) > } > exit(EXIT_SUCCESS); > break; > - case 'E': > + case 'E': { > int fd; > fd = open(optarg, O_RDONLY); > if (fd < 0) > @@ -551,6 +551,7 @@ int main(int argc, char **argv) > printf("%d\n", bootdev); > exit(EXIT_SUCCESS); > break; > + } > case 'l': > loglevel = strtoul(optarg, NULL, 10); > break;
Hi Stefano, > Well, then we can simply move "int fd" before the "switch (c)", then it > is C99. sure, I will send a v2. > It seems we should add a test case in CI with clang, I always use gcc > and I do not get these errors (and yes, I was aware of this, but as gcc > didn't complain, it was ok to me).. Agreed. I will send a separate patch series, as I've noticed a few more things that could be improved in the CI setup while I'm at it. I need to correct myself, though: at least with Clang 18, this issue is only a compiler warning. It may have been different with Christian's older Clang version. Anyway, I think it's a good idea to fix warnings in general. Kind Regards, Michael
diff --git a/core/swupdate.c b/core/swupdate.c index dc818599..d0633c69 100644 --- a/core/swupdate.c +++ b/core/swupdate.c @@ -538,7 +538,7 @@ int main(int argc, char **argv) } exit(EXIT_SUCCESS); break; - case 'E': + case 'E': { int fd; fd = open(optarg, O_RDONLY); if (fd < 0) @@ -551,6 +551,7 @@ int main(int argc, char **argv) printf("%d\n", bootdev); exit(EXIT_SUCCESS); break; + } case 'l': loglevel = strtoul(optarg, NULL, 10); break;