]> git.ipfire.org Git - thirdparty/libvirt.git/commit
Fix build with GCC 8 new switch fallthrough warnings
authorDaniel P. Berrangé <berrange@redhat.com>
Tue, 13 Feb 2018 11:28:45 +0000 (11:28 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Tue, 20 Feb 2018 15:30:59 +0000 (15:30 +0000)
commit75f4813c7da3d86f97bd45ae94297d28fb80f243
tree09a130a1da4e1a30dd42d9ad308362da7ffa968b
parenta302480dcb17acb759b0034b3d5ae70a0fb5e9da
Fix build with GCC 8 new switch fallthrough warnings

GCC 8 became more fussy about detecting switch
fallthroughs. First it doesn't like it if you have
a fallthrough attribute that is not before a case
statement. e.g.

   FOO:
   BAR:
   WIZZ:
      ATTRIBUTE_FALLTHROUGH;

Is unacceptable as there's no final case statement,
so while FOO & BAR are falling through, WIZZ is
not falling through. IOW, GCC wants us to write

  FOO:
  BAR:
    ATTRIBUTE_FALLTHROUGH;
  WIZZ:

Second, it will report risk of fallthrough even if you
have a case statement for every single enum value, but
only if the switch is nested inside another switch and
the outer case statement has no final break. This is
is arguably valid because despite the fact that we have
cast from "int" to the enum typedef, nothing guarantees
that the variable we're switching on only contains values
that have corresponding switch labels. e.g.

   int domstate = 87539319;
   switch ((virDomainState)domstate) {
      ...
   }

will not match enum value, but also not raise any kind
of compiler warning. So it is right to complain about
risk of fallthrough if no default: is present.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/qemu/qemu_domain.c
src/qemu/qemu_domain_address.c