From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36624) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VgHBJ-0000oS-7i for qemu-devel@nongnu.org; Tue, 12 Nov 2013 11:51:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VgHBC-0000yu-9a for qemu-devel@nongnu.org; Tue, 12 Nov 2013 11:51:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:7765) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VgHBB-0000yU-QF for qemu-devel@nongnu.org; Tue, 12 Nov 2013 11:51:06 -0500 Message-ID: <52825C75.3050505@redhat.com> Date: Tue, 12 Nov 2013 09:51:01 -0700 From: Eric Blake MIME-Version: 1.0 References: <1383766420-20745-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1383766420-20745-3-git-send-email-xiawenc@linux.vnet.ibm.com> In-Reply-To: <1383766420-20745-3-git-send-email-xiawenc@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="9asAuNe0sg4sAGKcmk4AdU4LCnExjwaKq" Subject: Re: [Qemu-devel] [PATCH 2/8] qapi script: report error for default case in union visit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wenchao Xia , qemu-devel@nongnu.org Cc: kwolf@redhat.com, armbru@redhat.com, mdroth@linux.vnet.ibm.com, lcapitulino@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --9asAuNe0sg4sAGKcmk4AdU4LCnExjwaKq Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 11/06/2013 12:33 PM, Wenchao Xia wrote: > It is possible to reach default case, when an union have a enum > discriminator, so don't abort() but report the error message. >=20 > Signed-off-by: Wenchao Xia > --- > scripts/qapi-visit.py | 14 ++++++++++++-- > 1 files changed, 12 insertions(+), 2 deletions(-) I still think this is not ideal. You are proposing a runtime error: > + # Tell caller the value is invalid, since the discriminator value = maybe an > + # unmapped enum value. > ret +=3D mcgen(''' > default: > - abort(); > + error_setg(&err, > + "Invalid discriminator value %(pi)s for %(n= ame)s", > + (*obj)->kind); > + break; > } whereas I'm requesting a compile-time error - it is much easier for maintenance reasons to have the generator require up-front that all enum values are covered, and loudly complain if an enum type is extended without also extending the use of that enum type in a union, than it is to silently generate a runtime error and wait for the bug reports several weeks down the road. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --9asAuNe0sg4sAGKcmk4AdU4LCnExjwaKq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.15 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEbBAEBCAAGBQJSglx1AAoJEKeha0olJ0NqXqwH+JvjNL4kkuBMxeNUD73MT9fx opmC+TJBPhQdKIUMoNEa/yXM4DCwIqylUOmevXKwREk0y2NtyrDFg71GYZw+VV+J U4XgZMo9cvwZLS66R++l5cf5cZrHFQFrpOxtLD46uV5O95weRkN9RM/L1wkZhn2K mS7DGjWAvMaAadCtqy/JLkIAFfhtJdqP6bb1TK1wIo8ESgT6s9Te2cFjdooJ7yZI 17W8BnFp5rzZht/rOd3kRFH20rZFk4+6HpAtzvilks47pCWx6m0DwnBp8hf8Weer RRQ8zpZ8OcIwTMhMm0ms9yPZHmNYSZrXhEKcZ4YOiZAaRFGQ3ruo9/A0mHf8OQ== =lF4A -----END PGP SIGNATURE----- --9asAuNe0sg4sAGKcmk4AdU4LCnExjwaKq--