Skip to contentSkip to conversation

fix GCC enum warning

PATCH In review Rosen Penev 2 participants 5 messages Aug 3, 2020 – Sep 10, 2020 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fix GCC enum warning

Found with -Wenum-compare

../utils/common/v4l-helpers.h:880:36: warning: enumerated and non-enumerated type in conditional expression [-Wextra]
880 | return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;

---
v2: Added warning message.

 utils/common/v4l-helpers.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
utils/common/v4l-helpers.h +1 -1
index e093e717..edd21c16 100644
@@ -877,7 +877,7 @@ v4l_format_g_hsv_enc(const struct v4l2_format *fmt)
 {
 	unsigned hsv_enc = v4l_format_g_ycbcr_enc(fmt);
 
-	return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;
+	return hsv_enc < V4L2_HSV_ENC_180 ? unsigned(V4L2_HSV_ENC_180) : hsv_enc;
 }
 
 static inline void v4l_format_s_quantization(struct v4l2_format *fmt,
Signature · 1 line
2.26.2
#1 lore raw
Quoted 17 lines · Rosen Penev

Found with -Wenum-compare

../utils/common/v4l-helpers.h:880:36: warning: enumerated and non-enumerated type in conditional expression [-Wextra]
880 | return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;

---
v2: Added warning message.

 utils/common/v4l-helpers.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
utils/common/v4l-helpers.h +0 -0
index e093e717..edd21c16 100644

utils/common/v4l-helpers.h v4l_format_g_hsv_enc(const struct v4l2_format *fmt) · line 878

Quoted 2 lines
utils/common/v4l-helpers.h +0 -0
@@ -877,7 +877,7 @@ v4l_format_g_hsv_enc(const struct v4l2_format *fmt)
 {
 	unsigned hsv_enc = v4l_format_g_ycbcr_enc(fmt);

Does the warning go away if you replace 'unsigned' with enum v4l2_hsv_encoding?

I would like that a lot better than casting V4L2_HSV_ENC_180.

Regards,

Hans

Quoted 7 lines
utils/common/v4l-helpers.h +1 -1
-	return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;
+	return hsv_enc < V4L2_HSV_ENC_180 ? unsigned(V4L2_HSV_ENC_180) : hsv_enc;
 }
 
 static inline void v4l_format_s_quantization(struct v4l2_format *fmt,
 
#2 lore raw
Quoted 14 lines · Hans Verkuil
Quoted 12 lines · Rosen Penev

Found with -Wenum-compare

../utils/common/v4l-helpers.h:880:36: warning: enumerated and non-enumerated type in conditional expression [-Wextra]
880 | return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;

---
v2: Added warning message.

 utils/common/v4l-helpers.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 9 lines

utils/common/v4l-helpers.h v4l_format_g_hsv_enc(const struct v4l2_format *fmt) · line 878

Quoted 7 lines
utils/common/v4l-helpers.h +0 -0
index e093e717..edd21c16 100644
@@ -877,7 +877,7 @@ v4l_format_g_hsv_enc(const struct v4l2_format *fmt)
 {
      unsigned hsv_enc = v4l_format_g_ycbcr_enc(fmt);

Does the warning go away if you replace 'unsigned' with enum v4l2_hsv_encoding?

../utils/common/v4l-helpers.h:878:25: error: cannot initialize a variable of type 'enum v4l2_hsv_encoding' with an rvalue of type 'unsigned int'

        enum v4l2_hsv_encoding hsv_enc = v4l_format_g_ycbcr_enc(fmt);
Quoted 15 lines

I would like that a lot better than casting V4L2_HSV_ENC_180.

Regards,

Hans

Quoted 7 lines
utils/common/v4l-helpers.h +1 -1
-     return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;
+     return hsv_enc < V4L2_HSV_ENC_180 ? unsigned(V4L2_HSV_ENC_180) : hsv_enc;
 }
 
 static inline void v4l_format_s_quantization(struct v4l2_format *fmt,
 
#3 lore raw
Quoted 24 lines · Rosen Penev
Quoted 14 lines · Hans Verkuil
Quoted 12 lines · Rosen Penev

Found with -Wenum-compare

../utils/common/v4l-helpers.h:880:36: warning: enumerated and non-enumerated type in conditional expression [-Wextra]
880 | return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;

---
v2: Added warning message.

 utils/common/v4l-helpers.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 9 lines

utils/common/v4l-helpers.h v4l_format_g_hsv_enc(const struct v4l2_format *fmt) · line 878

Quoted 7 lines
utils/common/v4l-helpers.h +0 -0
index e093e717..edd21c16 100644
@@ -877,7 +877,7 @@ v4l_format_g_hsv_enc(const struct v4l2_format *fmt)
 {
      unsigned hsv_enc = v4l_format_g_ycbcr_enc(fmt);

Does the warning go away if you replace 'unsigned' with enum v4l2_hsv_encoding?

Quoted 4 lines

../utils/common/v4l-helpers.h:878:25: error: cannot initialize a variable of type 'enum v4l2_hsv_encoding' with an rvalue of type 'unsigned int'

        enum v4l2_hsv_encoding hsv_enc = v4l_format_g_ycbcr_enc(fmt);

Urgh.

How about this:

	if (hsv_enc < V4L2_HSV_ENC_180)
		return V4L2_HSV_ENC_180;
	return hsv_enc;

Regards,

Hans

Quoted 16 lines
Quoted 16 lines

I would like that a lot better than casting V4L2_HSV_ENC_180.

Regards,

Hans

Quoted 7 lines
utils/common/v4l-helpers.h +1 -1
-     return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;
+     return hsv_enc < V4L2_HSV_ENC_180 ? unsigned(V4L2_HSV_ENC_180) : hsv_enc;
 }
 
 static inline void v4l_format_s_quantization(struct v4l2_format *fmt,
 
#4 lore raw
Quoted 31 lines · Hans Verkuil
Quoted 24 lines · Rosen Penev
Quoted 14 lines · Hans Verkuil
Quoted 12 lines · Rosen Penev

Found with -Wenum-compare

../utils/common/v4l-helpers.h:880:36: warning: enumerated and non-enumerated type in conditional expression [-Wextra]
880 | return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;

---
v2: Added warning message.

 utils/common/v4l-helpers.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 9 lines

utils/common/v4l-helpers.h v4l_format_g_hsv_enc(const struct v4l2_format *fmt) · line 878

Quoted 7 lines
utils/common/v4l-helpers.h +0 -0
index e093e717..edd21c16 100644
@@ -877,7 +877,7 @@ v4l_format_g_hsv_enc(const struct v4l2_format *fmt)
 {
      unsigned hsv_enc = v4l_format_g_ycbcr_enc(fmt);

Does the warning go away if you replace 'unsigned' with enum v4l2_hsv_encoding?

Quoted 4 lines

../utils/common/v4l-helpers.h:878:25: error: cannot initialize a variable of type 'enum v4l2_hsv_encoding' with an rvalue of type 'unsigned int'

        enum v4l2_hsv_encoding hsv_enc = v4l_format_g_ycbcr_enc(fmt);
Quoted 7 lines

Urgh.

How about this:

        if (hsv_enc < V4L2_HSV_ENC_180)
                return V4L2_HSV_ENC_180;
        return hsv_enc;

Huh. That seems to have done it.

Quoted 22 lines

Regards,

Hans

Quoted 16 lines
Quoted 16 lines

I would like that a lot better than casting V4L2_HSV_ENC_180.

Regards,

Hans

Quoted 7 lines
utils/common/v4l-helpers.h +1 -1
-     return hsv_enc < V4L2_HSV_ENC_180 ? V4L2_HSV_ENC_180 : hsv_enc;
+     return hsv_enc < V4L2_HSV_ENC_180 ? unsigned(V4L2_HSV_ENC_180) : hsv_enc;
 }
 
 static inline void v4l_format_s_quantization(struct v4l2_format *fmt,