[PATCH] ip: Wrap CASE macro body in braces for pre-C23 compatibility
From: Jeskynar
On Mon, May 18, 2026 at 07:28:06PM +0530, Anshu Kumari wrote:
From: Jeskynar
Compiling on RHEL8 (gcc-8.5) gives an error in ip.c. ip.c:88:3: error: a label can only be part of a statement and a declaration is not a statement due to the use of static_assert.
The fix is to surround it with {}.
Link: https://bugs.passt.top/show_bug.cgi?id=201 Signed-off-by: Anshu Kumari
Reviewed-by: David Gibson
--- ip.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/ip.c b/ip.c index f2506bb..7b674e0 100644 --- a/ip.c +++ b/ip.c @@ -35,9 +35,9 @@ const char *ipproto_name(uint8_t proto) { switch (proto) { #define CASE(s) \ - static_assert(sizeof(s) <= IPPROTO_STRLEN, \ - "Increase IPPROTO_STRLEN to contain " #s); \ - return s; + {static_assert(sizeof(s) <= IPPROTO_STRLEN, \ + "Increase IPPROTO_STRLEN to contain " #s); \ + return s;} case IPPROTO_ICMP: CASE("ICMP"); case IPPROTO_TCP: -- 2.54.0
-- David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson
On 5/18/26 15:58, Anshu Kumari wrote:
From: Jeskynar
Compiling on RHEL8 (gcc-8.5) gives an error in ip.c. ip.c:88:3: error: a label can only be part of a statement and a declaration is not a statement due to the use of static_assert.
The fix is to surround it with {}.
Link: https://bugs.passt.top/show_bug.cgi?id=201 Signed-off-by: Anshu Kumari
Fixes: 93c3e351f235 ("ip: Define a bound for the string returned by ipproto_name()")
Reviewed-by: Laurent Vivier
--- ip.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/ip.c b/ip.c index f2506bb..7b674e0 100644 --- a/ip.c +++ b/ip.c @@ -35,9 +35,9 @@ const char *ipproto_name(uint8_t proto) { switch (proto) { #define CASE(s) \ - static_assert(sizeof(s) <= IPPROTO_STRLEN, \ - "Increase IPPROTO_STRLEN to contain " #s); \ - return s; + {static_assert(sizeof(s) <= IPPROTO_STRLEN, \ + "Increase IPPROTO_STRLEN to contain " #s); \ + return s;} case IPPROTO_ICMP: CASE("ICMP"); case IPPROTO_TCP:
On Mon, 18 May 2026 19:28:06 +0530
Anshu Kumari
From: Jeskynar
Compiling on RHEL8 (gcc-8.5) gives an error in ip.c. ip.c:88:3: error: a label can only be part of a statement and a declaration is not a statement due to the use of static_assert.
The fix is to surround it with {}.
Link: https://bugs.passt.top/show_bug.cgi?id=201 Signed-off-by: Anshu Kumari
--- ip.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ip.c b/ip.c index f2506bb..7b674e0 100644 --- a/ip.c +++ b/ip.c @@ -35,9 +35,9 @@ const char *ipproto_name(uint8_t proto) { switch (proto) { #define CASE(s) \ - static_assert(sizeof(s) <= IPPROTO_STRLEN, \ - "Increase IPPROTO_STRLEN to contain " #s); \ - return s; + {static_assert(sizeof(s) <= IPPROTO_STRLEN, \ + "Increase IPPROTO_STRLEN to contain " #s); \ + return s;}
One minor detail, which I would usually fix up on merge, but in this case it's half of the patch...: our coding style always has code blocks separated by newlines and indented, that is, in this case: { static_assert(sizeof(s) <= IPPROTO_STRLEN, \ "Increase IPPROTO_STRLEN to contain " \ #s); \ return s; } and in these cases I would suggest to add (perhaps I mentioned it already?) something like "Based on a patch from ..." blah. Then before your Signed-off-by you can describe shortly what you changed in square brackets. Just grep for "Based on" in the git log, you'll find plenty of (rather consistent) examples. -- Stefano
participants (4)
-
Anshu Kumari
-
David Gibson
-
Laurent Vivier
-
Stefano Brivio