Skip to contentSkip to conversation

connector, linux++: fix <uapi/linux/cn_proc.h> header

PATCH In review Alexey Dobriyan 2 participants 2 messages Jan 23, 2024 – Jan 24, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 connector, linux++: fix <uapi/linux/cn_proc.h> header

Rules around enums are stricter in C++, they decay to ints just as easily but don't convert back to enums:

	#define PROC_EVENT_ALL (PROC_EVENT_FORK|...)
	enum proc_cn_event ev_type;
	ev_type &= PROC_EVENT_ALL;

main.cc: In function ‘proc_cn_event valid_event(proc_cn_event)’:
main.cc:91:17: error: invalid conversion from ‘unsigned int’ to ‘proc_cn_event’ [-fpermissive]

   91 |         ev_type &= PROC_EVENT_ALL;
      |                 ^
      |                 |
      |                 unsigned int

Use casts so that both C and C++ compilers are satisfied.

---

 include/uapi/linux/cn_proc.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
include/uapi/linux/cn_proc.h +1 -2
@@ -69,8 +69,7 @@ struct proc_input {
 
 static inline enum proc_cn_event valid_event(enum proc_cn_event ev_type)
 {
-	ev_type &= PROC_EVENT_ALL;
-	return ev_type;
+	return (enum proc_cn_event)(ev_type & PROC_EVENT_ALL)
 }
 
 /*
Signature · 1 line
2.43.0
reviewer
#1 lore raw
Quoted 25 lines · Alexey Dobriyan

Rules around enums are stricter in C++, they decay to ints just as easily but don't convert back to enums:

	#define PROC_EVENT_ALL (PROC_EVENT_FORK|...)
	enum proc_cn_event ev_type;
	ev_type &= PROC_EVENT_ALL;

main.cc: In function ‘proc_cn_event valid_event(proc_cn_event)’:
main.cc:91:17: error: invalid conversion from ‘unsigned int’ to ‘proc_cn_event’ [-fpermissive]

   91 |         ev_type &= PROC_EVENT_ALL;
      |                 ^
      |                 |
      |                 unsigned int

Use casts so that both C and C++ compilers are satisfied.

---

 include/uapi/linux/cn_proc.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

include/uapi/linux/cn_proc.h struct proc_input { · line 72

Quoted 6 lines
include/uapi/linux/cn_proc.h +1 -2
@@ -69,8 +69,7 @@ struct proc_input {
 
 static inline enum proc_cn_event valid_event(enum proc_cn_event ev_type)
 {
-	ev_type &= PROC_EVENT_ALL;
-	return ev_type;
+	return (enum proc_cn_event)(ev_type & PROC_EVENT_ALL)

Hi Alexey,

I think the line above needs a ; at the end of it.

Quoted 6 lines
include/uapi/linux/cn_proc.h +0 -0
 }
 
 /*
Signature · 1 line
2.43.0