]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Add fake switch statement to warn for new device types
authorPeter Krempa <pkrempa@redhat.com>
Thu, 21 Feb 2013 11:37:59 +0000 (12:37 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 25 Feb 2013 08:36:24 +0000 (09:36 +0100)
This patch adds a fake switch statement to force the compiler to warn
after a new device type was added. This should remind the contributor to
add the new device also to this iterator function.

src/conf/domain_conf.c

index 0c75838bcc76ebab914d0bc6a0d17216f52e34f5..13c414152856da630323658a7aecd502c35cd571 100644 (file)
@@ -2348,6 +2348,35 @@ int virDomainDeviceInfoIterate(virDomainDefPtr def,
         if (cb(def, &device, &def->hubs[i]->info, opaque) < 0)
             return -1;
     }
+
+    /* This switch statement is here to trigger compiler warning when adding
+     * a new device type. When you are adding a new field to the swtich you
+     * also have to add a iteration statement above. Otherwise the switch
+     * statement has no real function here and should be optimized out by the
+     * compiler. */
+    i = VIR_DOMAIN_DEVICE_LAST;
+    switch ((virDomainDeviceType) i) {
+    case VIR_DOMAIN_DEVICE_DISK:
+    case VIR_DOMAIN_DEVICE_LEASE:
+    case VIR_DOMAIN_DEVICE_FS:
+    case VIR_DOMAIN_DEVICE_NET:
+    case VIR_DOMAIN_DEVICE_INPUT:
+    case VIR_DOMAIN_DEVICE_SOUND:
+    case VIR_DOMAIN_DEVICE_VIDEO:
+    case VIR_DOMAIN_DEVICE_HOSTDEV:
+    case VIR_DOMAIN_DEVICE_WATCHDOG:
+    case VIR_DOMAIN_DEVICE_CONTROLLER:
+    case VIR_DOMAIN_DEVICE_GRAPHICS:
+    case VIR_DOMAIN_DEVICE_HUB:
+    case VIR_DOMAIN_DEVICE_REDIRDEV:
+    case VIR_DOMAIN_DEVICE_NONE:
+    case VIR_DOMAIN_DEVICE_SMARTCARD:
+    case VIR_DOMAIN_DEVICE_CHR:
+    case VIR_DOMAIN_DEVICE_MEMBALLOON:
+    case VIR_DOMAIN_DEVICE_LAST:
+        break;
+    }
+
     return 0;
 }