[parted-devel] GCC unhappy with "case PED_EXCEPTION_OK_CANCEL:"

D. Hugh Redelmeier hugh at mimosa.com
Sun Jun 27 22:48:35 BST 2021


I'm compiling fatresize.  It uses parted/exception.h

I get a warning from GCC:
fatresize.c:319:9: warning: case value ‘96’ not in enumerated type 
‘PedExceptionOption’ [-Wswitch]
  319 |         case PED_EXCEPTION_IGNORE_CANCEL:
      |         ^~~~

The problem is that the case is on a value of type enum 
_PedExceptionOption and PED_EXCEPTION_IGNORE_CANCEL is not a valid
value of that enum type.

The fix is simple: just annex the #defines for combinations of options
into the enum itself.  I don't see a downside.  UNTESTED.

================
$ diff -u exception.h exception.h.new
--- exception.h	2021-01-27 18:33:19.000000000 -0500
+++ exception.h.new	2021-06-27 17:37:47.306718343 -0400
@@ -46,6 +46,7 @@
  * Option for resolving the exception
  */
 enum _PedExceptionOption {
+	/* individual options */
 	PED_EXCEPTION_UNHANDLED=0,
 	PED_EXCEPTION_FIX=1,
 	PED_EXCEPTION_YES=2,
@@ -54,19 +55,23 @@
 	PED_EXCEPTION_RETRY=16,
 	PED_EXCEPTION_IGNORE=32,
 	PED_EXCEPTION_CANCEL=64,
+
+	/* combinations of individual options */
+	PED_EXCEPTION_OK_CANCEL = PED_EXCEPTION_OK + PED_EXCEPTION_CANCEL,
+	PED_EXCEPTION_YES_NO = PED_EXCEPTION_YES + PED_EXCEPTION_NO,
+	PED_EXCEPTION_YES_NO_CANCEL =
+		PED_EXCEPTION_YES_NO + PED_EXCEPTION_CANCEL,
+	PED_EXCEPTION_IGNORE_CANCEL =
+		PED_EXCEPTION_IGNORE + PED_EXCEPTION_CANCEL,
+	PED_EXCEPTION_RETRY_CANCEL = PED_EXCEPTION_RETRY + PED_EXCEPTION_CANCEL,
+	PED_EXCEPTION_RETRY_IGNORE_CANCEL =
+		PED_EXCEPTION_RETRY + PED_EXCEPTION_IGNORE_CANCEL,
 };
-typedef enum _PedExceptionOption PedExceptionOption;
-#define PED_EXCEPTION_OK_CANCEL	    (PED_EXCEPTION_OK + PED_EXCEPTION_CANCEL)
-#define PED_EXCEPTION_YES_NO	    (PED_EXCEPTION_YES + PED_EXCEPTION_NO)
-#define PED_EXCEPTION_YES_NO_CANCEL (PED_EXCEPTION_YES_NO \
-				     + PED_EXCEPTION_CANCEL)
-#define PED_EXCEPTION_IGNORE_CANCEL (PED_EXCEPTION_IGNORE \
-				     + PED_EXCEPTION_CANCEL)
-#define PED_EXCEPTION_RETRY_CANCEL  (PED_EXCEPTION_RETRY + PED_EXCEPTION_CANCEL)
-#define PED_EXCEPTION_RETRY_IGNORE_CANCEL (PED_EXCEPTION_RETRY \
-					   + PED_EXCEPTION_IGNORE_CANCEL)
+
 #define PED_EXCEPTION_OPTION_FIRST PED_EXCEPTION_FIX
-#define PED_EXCEPTION_OPTION_LAST PED_EXCEPTION_CANCEL
+#define PED_EXCEPTION_OPTION_LAST PED_EXCEPTION_CANCEL	/* last individual option */
+
+typedef enum _PedExceptionOption PedExceptionOption;
 
 /**
  * Structure with information about exception
================


More information about the parted-devel mailing list