提交 5d84f596 编写于 作者: D Daniel P. Berrange

Add ATTRIBUTE_FALLTHROUGH for switch cases without break

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: NDaniel P. Berrange <berrange@redhat.com>
上级 fb52faf8
...@@ -14935,6 +14935,9 @@ virDomainChrEquals(virDomainChrDefPtr src, ...@@ -14935,6 +14935,9 @@ virDomainChrEquals(virDomainChrDefPtr src,
case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL: case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL:
if (src->targetTypeAttr != tgt->targetTypeAttr) if (src->targetTypeAttr != tgt->targetTypeAttr)
return false; return false;
ATTRIBUTE_FALLTHROUGH;
case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE: case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL: case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
return src->target.port == tgt->target.port; return src->target.port == tgt->target.port;
...@@ -22158,6 +22161,8 @@ virDomainChrDefFormat(virBufferPtr buf, ...@@ -22158,6 +22161,8 @@ virDomainChrDefFormat(virBufferPtr buf,
def->target.port); def->target.port);
break; break;
} }
ATTRIBUTE_FALLTHROUGH;
default: default:
virBufferAsprintf(buf, "<target port='%d'/>\n", virBufferAsprintf(buf, "<target port='%d'/>\n",
def->target.port); def->target.port);
......
...@@ -2442,7 +2442,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt) ...@@ -2442,7 +2442,8 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
def->name); def->name);
goto error; goto error;
} }
/* fall through to next case */ ATTRIBUTE_FALLTHROUGH;
case VIR_NETWORK_FORWARD_BRIDGE: case VIR_NETWORK_FORWARD_BRIDGE:
if (def->delay || stp) { if (def->delay || stp) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
......
...@@ -218,6 +218,14 @@ ...@@ -218,6 +218,14 @@
# endif # endif
# 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 # else
# ifndef ATTRIBUTE_UNUSED # ifndef ATTRIBUTE_UNUSED
# define ATTRIBUTE_UNUSED # define ATTRIBUTE_UNUSED
...@@ -228,6 +236,10 @@ ...@@ -228,6 +236,10 @@
# ifndef ATTRIBUTE_RETURN_CHECK # ifndef ATTRIBUTE_RETURN_CHECK
# define ATTRIBUTE_RETURN_CHECK # define ATTRIBUTE_RETURN_CHECK
# endif # endif
#
# ifndef ATTRIBUTE_FALLTHROUGH
# define ATTRIBUTE_FALLTHROUGH do {} while(0)
# endif
# endif /* __GNUC__ */ # endif /* __GNUC__ */
......
...@@ -2042,7 +2042,7 @@ static int lxcContainerDropCapabilities(virDomainDefPtr def, ...@@ -2042,7 +2042,7 @@ static int lxcContainerDropCapabilities(virDomainDefPtr def,
default: /* User specified capabilities to drop */ default: /* User specified capabilities to drop */
toDrop = (state == VIR_TRISTATE_SWITCH_OFF); toDrop = (state == VIR_TRISTATE_SWITCH_OFF);
} }
/* Fallthrough */ ATTRIBUTE_FALLTHROUGH;
case VIR_DOMAIN_CAPABILITIES_POLICY_ALLOW: case VIR_DOMAIN_CAPABILITIES_POLICY_ALLOW:
if (policy == VIR_DOMAIN_CAPABILITIES_POLICY_ALLOW) if (policy == VIR_DOMAIN_CAPABILITIES_POLICY_ALLOW)
......
...@@ -2715,6 +2715,8 @@ networkStartNetwork(virNetworkDriverStatePtr driver, ...@@ -2715,6 +2715,8 @@ networkStartNetwork(virNetworkDriverStatePtr driver,
* VIR_NETWORK_FORWARD_BRIDGE with no bridge device defined * VIR_NETWORK_FORWARD_BRIDGE with no bridge device defined
* (since that is macvtap bridge mode). * (since that is macvtap bridge mode).
*/ */
ATTRIBUTE_FALLTHROUGH;
case VIR_NETWORK_FORWARD_PRIVATE: case VIR_NETWORK_FORWARD_PRIVATE:
case VIR_NETWORK_FORWARD_VEPA: case VIR_NETWORK_FORWARD_VEPA:
case VIR_NETWORK_FORWARD_PASSTHROUGH: case VIR_NETWORK_FORWARD_PASSTHROUGH:
...@@ -2792,6 +2794,8 @@ networkShutdownNetwork(virNetworkDriverStatePtr driver, ...@@ -2792,6 +2794,8 @@ networkShutdownNetwork(virNetworkDriverStatePtr driver,
* VIR_NETWORK_FORWARD_BRIDGE with no bridge device defined * VIR_NETWORK_FORWARD_BRIDGE with no bridge device defined
* (since that is macvtap bridge mode). * (since that is macvtap bridge mode).
*/ */
ATTRIBUTE_FALLTHROUGH;
case VIR_NETWORK_FORWARD_PRIVATE: case VIR_NETWORK_FORWARD_PRIVATE:
case VIR_NETWORK_FORWARD_VEPA: case VIR_NETWORK_FORWARD_VEPA:
case VIR_NETWORK_FORWARD_PASSTHROUGH: case VIR_NETWORK_FORWARD_PASSTHROUGH:
...@@ -4974,6 +4978,8 @@ networkGetNetworkAddress(const char *netname, char **netaddr) ...@@ -4974,6 +4978,8 @@ networkGetNetworkAddress(const char *netname, char **netaddr)
* fall through if netdef->bridge wasn't set, since that is * fall through if netdef->bridge wasn't set, since that is
* macvtap bridge mode network. * macvtap bridge mode network.
*/ */
ATTRIBUTE_FALLTHROUGH;
case VIR_NETWORK_FORWARD_PRIVATE: case VIR_NETWORK_FORWARD_PRIVATE:
case VIR_NETWORK_FORWARD_VEPA: case VIR_NETWORK_FORWARD_VEPA:
case VIR_NETWORK_FORWARD_PASSTHROUGH: case VIR_NETWORK_FORWARD_PASSTHROUGH:
......
...@@ -140,7 +140,7 @@ do { ...@@ -140,7 +140,7 @@ do {
goto redefine; goto redefine;
break; break;
} }
/* fall-through */ ATTRIBUTE_FALLTHROUGH;
#endif #endif
default: default:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册