diff mbox series

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

Message ID 3878dc5a-9046-4d7a-bf9e-70dcdc5d9265@p183 (mailing list archive)
State Changes Requested
Headers show
Series [1/2] connector: fix #include <linux/cn_proc.h> | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Alexey Dobriyan Jan. 23, 2024, 10:16 a.m. UTC
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.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

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

Comments

Simon Horman Jan. 24, 2024, 8:40 a.m. UTC | #1
On Tue, Jan 23, 2024 at 01:16:46PM +0300, Alexey Dobriyan wrote:
> 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.
> 
> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> ---
> 
>  include/uapi/linux/cn_proc.h | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> --- a/include/uapi/linux/cn_proc.h
> +++ b/include/uapi/linux/cn_proc.h
> @@ -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.

>  }
>  
>  /*
> -- 
> 2.43.0
>
diff mbox series

Patch

--- a/include/uapi/linux/cn_proc.h
+++ b/include/uapi/linux/cn_proc.h
@@ -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)
 }
 
 /*