]> xenbits.xensource.com Git - libvirt.git/commitdiff
Add ATTRIBUTE_FALLTHROUGH for switch cases without break
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 22 Feb 2017 17:37:09 +0000 (17:37 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 23 Feb 2017 10:11:16 +0000 (10:11 +0000)
In GCC 7 there is a new warning triggered when a switch
case has a conditional statement (eg if ... else...) and
some of the code paths fallthrough to the next switch
statement. e.g.

conf/domain_conf.c: In function 'virDomainChrEquals':
conf/domain_conf.c:14926:12: error: this statement may fall through [-Werror=implicit-fallthrough=]
         if (src->targetTypeAttr != tgt->targetTypeAttr)
            ^
conf/domain_conf.c:14928:5: note: here
     case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
     ^~~~
conf/domain_conf.c: In function 'virDomainChrDefFormat':
conf/domain_conf.c:22143:12: error: this statement may fall through [-Werror=implicit-fallthrough=]
         if (def->targetTypeAttr) {
            ^
conf/domain_conf.c:22151:5: note: here
     default:
     ^~~~~~~

GCC introduced a __attribute__((fallthrough)) to let you
indicate that this is intentionale behaviour rather than
a bug.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/conf/domain_conf.c
src/conf/network_conf.c
src/internal.h
src/lxc/lxc_container.c
src/network/bridge_driver.c
tools/virsh-edit.c

index b7b5b7e7d7abda2f6fd8c66a9ba500173f160a99..97d42fe993ba121a58098dc1d4f3b3b171cc4ce7 100644 (file)
@@ -14935,6 +14935,9 @@ virDomainChrEquals(virDomainChrDefPtr src,
     case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL:
         if (src->targetTypeAttr != tgt->targetTypeAttr)
             return false;
+
+        ATTRIBUTE_FALLTHROUGH;
+
     case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
     case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
         return src->target.port == tgt->target.port;
@@ -22158,6 +22161,8 @@ virDomainChrDefFormat(virBufferPtr buf,
                               def->target.port);
             break;
         }
+        ATTRIBUTE_FALLTHROUGH;
+
     default:
         virBufferAsprintf(buf, "<target port='%d'/>\n",
                           def->target.port);
index 0e20dac074dac97623e7e9c9fdad6d5dda19f136..48e0001899e9a77340d0e9315cfe85ff358a5285 100644 (file)
@@ -2442,7 +2442,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
                            def->name);
             goto error;
         }
-        /* fall through to next case */
+        ATTRIBUTE_FALLTHROUGH;
+
     case VIR_NETWORK_FORWARD_BRIDGE:
         if (def->delay || stp) {
             virReportError(VIR_ERR_XML_ERROR,
index 334659d329d42528355fb12533d0604a5d5e4591..d64be93b348a1ff89d52808414db359624d27bb0 100644 (file)
 #   endif
 #  endif
 
+#  ifndef ATTRIBUTE_FALLTHROUGH
+#   if __GNUC_PREREQ (7, 0)
+#    define ATTRIBUTE_FALLTHROUGH __attribute__((fallthrough))
+#   else
+#    define ATTRIBUTE_FALLTHROUGH do {} while(0)
+#   endif
+#  endif
+
 # else
 #  ifndef ATTRIBUTE_UNUSED
 #   define ATTRIBUTE_UNUSED
 #  ifndef ATTRIBUTE_RETURN_CHECK
 #   define ATTRIBUTE_RETURN_CHECK
 #  endif
+#
+#  ifndef ATTRIBUTE_FALLTHROUGH
+#   define ATTRIBUTE_FALLTHROUGH do {} while(0)
+#  endif
 # endif                                /* __GNUC__ */
 
 
index 601b9b03575c4456921fcbf58e3ce1cbd18f5609..99bd7e9446a6cbcd8426244d74916cc28da3c992 100644 (file)
@@ -2042,7 +2042,7 @@ static int lxcContainerDropCapabilities(virDomainDefPtr def,
             default: /* User specified capabilities to drop */
                 toDrop = (state == VIR_TRISTATE_SWITCH_OFF);
             }
-            /* Fallthrough */
+            ATTRIBUTE_FALLTHROUGH;
 
         case VIR_DOMAIN_CAPABILITIES_POLICY_ALLOW:
             if (policy == VIR_DOMAIN_CAPABILITIES_POLICY_ALLOW)
index 06759c643161ea1fa9551732eae311a6e43e056c..c5ec2823d319845d1f00ddfcd80a5027c9a4ee95 100644 (file)
@@ -2715,6 +2715,8 @@ networkStartNetwork(virNetworkDriverStatePtr driver,
          * VIR_NETWORK_FORWARD_BRIDGE with no bridge device defined
          * (since that is macvtap bridge mode).
          */
+        ATTRIBUTE_FALLTHROUGH;
+
     case VIR_NETWORK_FORWARD_PRIVATE:
     case VIR_NETWORK_FORWARD_VEPA:
     case VIR_NETWORK_FORWARD_PASSTHROUGH:
@@ -2792,6 +2794,8 @@ networkShutdownNetwork(virNetworkDriverStatePtr driver,
          * VIR_NETWORK_FORWARD_BRIDGE with no bridge device defined
          * (since that is macvtap bridge mode).
          */
+        ATTRIBUTE_FALLTHROUGH;
+
     case VIR_NETWORK_FORWARD_PRIVATE:
     case VIR_NETWORK_FORWARD_VEPA:
     case VIR_NETWORK_FORWARD_PASSTHROUGH:
@@ -4974,6 +4978,8 @@ networkGetNetworkAddress(const char *netname, char **netaddr)
          * fall through if netdef->bridge wasn't set, since that is
          * macvtap bridge mode network.
          */
+        ATTRIBUTE_FALLTHROUGH;
+
     case VIR_NETWORK_FORWARD_PRIVATE:
     case VIR_NETWORK_FORWARD_VEPA:
     case VIR_NETWORK_FORWARD_PASSTHROUGH:
index 16d6705fbbbdee73b3d5c087261aad7215015143..92a00b7f9ac5981d68253c290b3ecd5e9dcf2525 100644 (file)
@@ -140,7 +140,7 @@ do {
                 goto redefine;
                 break;
             }
-            /* fall-through */
+            ATTRIBUTE_FALLTHROUGH;
 #endif
 
         default: