qapi: Forbid empty unions and useless alternates
authorEric Blake <eblake@redhat.com>
Thu, 18 Feb 2016 06:48:16 +0000 (23:48 -0700)
committerMarkus Armbruster <armbru@redhat.com>
Fri, 19 Feb 2016 10:08:56 +0000 (11:08 +0100)
commit02a57ae32b08e8981b59979b80e682c9a153e94d
tree418d1597e1ea5ff8e3f119fe453e990746299fe3
parentf96493b1ab14e307495119064c32765f436b349c
qapi: Forbid empty unions and useless alternates

Empty unions serve no purpose, and while we compile with gcc
which permits them, strict C99 forbids them.  We happen to inject
a dummy 'void *data' member into the C unions that represent QAPI
unions and alternates, but we want to get rid of that member (it
pollutes the namespace for no good reason), which would leave us
with an empty union if the user didn't provide any branches.  While
empty structs make sense in QAPI, empty unions don't add any
expressiveness to the QMP language.  So prohibit them at parse
time.  Update the documentation and testsuite to match.

Note that the documentation already mentioned that alternates
should have "two or more JSON data types"; so this also fixes
the code to enforce that.  However, we have existing uses of a
union type with only one branch, so the 2-or-more strictness
is intentionally limited to alternates.

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1455778109-6278-3-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
14 files changed:
docs/qapi-code-gen.txt
scripts/qapi.py
tests/qapi-schema/alternate-empty.err
tests/qapi-schema/alternate-empty.exit
tests/qapi-schema/alternate-empty.json
tests/qapi-schema/alternate-empty.out
tests/qapi-schema/flat-union-empty.err
tests/qapi-schema/flat-union-empty.exit
tests/qapi-schema/flat-union-empty.json
tests/qapi-schema/flat-union-empty.out
tests/qapi-schema/union-empty.err
tests/qapi-schema/union-empty.exit
tests/qapi-schema/union-empty.json
tests/qapi-schema/union-empty.out