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

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

 



On 02/22/2017 11:52 AM, Daniel P. Berrange wrote:
> 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)
>             ^

> +++ 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;
> +

I understand this one...

>      case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
> +        ATTRIBUTE_FALLTHROUGH;
> +
>      case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:

...but was this one necessary, or is gcc smart enough to know that two
consecutive labels never needs an explicit fallthrough?

Also, is it sufficient to spell it:

/* fall through */

so that Coverity can also recognize it?  Or does gcc not recognize the
magic comment?

> +++ b/src/internal.h
> @@ -218,6 +218,10 @@
>  #   endif
>  #  endif
>  
> +#  ifndef ATTRIBUTE_FALLTHROUGH
> +#   define ATTRIBUTE_FALLTHROUGH __attribute__((fallthrough))
> +#  endif

If the magic /* fall through */ comment is sufficient, then we don't
need this macro.

> +++ 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;

Hmm - this argues at least one comment spelling that gcc does not recognize.


> +++ b/tools/virsh-edit.c
> @@ -140,7 +140,7 @@ do {
>                  goto redefine;
>                  break;
>              }
> -            /* fall-through */
> +            ATTRIBUTE_FALLTHROUGH;
>  #endif

and another.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
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