]> git.ipfire.org Git - thirdparty/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)
committerCole Robinson <crobinso@redhat.com>
Fri, 4 Aug 2017 19:49:49 +0000 (15:49 -0400)
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>
(cherry picked from commit 5d84f5961b8e28e802f600bb2d2c6903e219092e)

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 61f6dbbbaff2aa7e9f30d489f8961168e202ff19..c2c104488529d58a28496b6bf8cef8f2d8df4349 100644 (file)
@@ -14361,6 +14361,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;
@@ -21420,6 +21423,8 @@ virDomainChrDefFormat(virBufferPtr buf,
                               def->target.port);
             break;
         }
+        ATTRIBUTE_FALLTHROUGH;
+
     default:
         virBufferAsprintf(buf, "<target port='%d'/>\n",
                           def->target.port);
index aa397768c9c43441d425db2ad844b288ca57c126..af7e587b5462f590951bcffe897a52de42820b80 100644 (file)
@@ -2429,7 +2429,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 d8cc5adc38f35613bb1b7bf6ecba7c74e553226c..97a0f026937255471e8065e3b9aa0cf1fee4c159 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 5357df48de587375ca1b308d20c3276ebc21736b..ed10d6da16d7224f4cfe64783d4f0aed6f217ea4 100644 (file)
@@ -2057,7 +2057,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 3cf349e46840de7ef2beee50e33952e84183958d..64e0d1a27b8db7c62bb7233e6118917febaed22b 100644 (file)
@@ -2565,6 +2565,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:
@@ -2642,6 +2644,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:
@@ -4816,6 +4820,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 1b39cb7d4525e2ade5e2c94d6134a134c7b72e69..1511114d223d18779f7bb939cf79f245ac6951cf 100644 (file)
@@ -140,7 +140,7 @@ do {
                 goto redefine;
                 break;
             }
-            /* fall-through */
+            ATTRIBUTE_FALLTHROUGH;
 #endif
 
         default: