[PATCH 4/4] Add ATTRIBUTE_FALLTHROUGH for switch cases without break

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/conf/domain_conf.c      | 7 +++++++
 src/conf/network_conf.c     | 3 ++-
 src/internal.h              | 8 ++++++++
 src/lxc/lxc_container.c     | 2 +-
 src/network/bridge_driver.c | 6 ++++++
 tools/virsh-edit.c          | 2 +-
 6 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f718b9a..17995f7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -14925,7 +14925,12 @@ 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:
+        ATTRIBUTE_FALLTHROUGH;
+
     case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
         return src->target.port == tgt->target.port;
         break;
@@ -22148,6 +22153,8 @@ virDomainChrDefFormat(virBufferPtr buf,
                               def->target.port);
             break;
         }
+        ATTRIBUTE_FALLTHROUGH;
+
     default:
         virBufferAsprintf(buf, "<target port='%d'/>\n",
                           def->target.port);
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 0e20dac..48e0001 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -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,
diff --git a/src/internal.h b/src/internal.h
index 334659d..74a43fa 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -218,6 +218,10 @@
 #   endif
 #  endif
 
+#  ifndef ATTRIBUTE_FALLTHROUGH
+#   define ATTRIBUTE_FALLTHROUGH __attribute__((fallthrough))
+#  endif
+
 # else
 #  ifndef ATTRIBUTE_UNUSED
 #   define ATTRIBUTE_UNUSED
@@ -228,6 +232,10 @@
 #  ifndef ATTRIBUTE_RETURN_CHECK
 #   define ATTRIBUTE_RETURN_CHECK
 #  endif
+#
+#  ifndef ATTRIBUTE_FALLTHROUGH
+#   define ATTRIBUTE_FALLTHROUGH do {} while(0)
+#  endif
 # endif				/* __GNUC__ */
 
 
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 601b9b0..99bd7e9 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -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)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 06759c6..c5ec282 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -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:
diff --git a/tools/virsh-edit.c b/tools/virsh-edit.c
index 16d6705..92a00b7 100644
--- a/tools/virsh-edit.c
+++ b/tools/virsh-edit.c
@@ -140,7 +140,7 @@ do {
                 goto redefine;
                 break;
             }
-            /* fall-through */
+            ATTRIBUTE_FALLTHROUGH;
 #endif
 
         default:
-- 
2.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux