rxgen: Generate default switch arm for void 98/14798/2
authorAndrew Deason <adeason@sinenomine.net>
Wed, 10 Feb 2021 22:42:16 +0000 (16:42 -0600)
committerBenjamin Kaduk <kaduk@mit.edu>
Thu, 16 Sep 2021 16:45:04 +0000 (12:45 -0400)
When defining an xdr union with a 'default' arm, rxgen generates xdr
routines like this:

    bool_t
    xdr_myunion(...)
    {
        switch (objp->op) {
        case FOO:
            xdr_foo(...);
            break;

        default:
            xdr_default(...);
            break;
        }
    }

However, if the default arm of the union is just 'void;', we just
don't generate a 'default:' arm in the switch statment in the
generated routines. If there are enum values that are not explicitly
specified, and are handled by the default arm, this generates a
compiler warning (which breaks the build for --enable-checking):

    foo_int.xdr.c:80:2 error: enumeration value 'BAR' not handled in switch [-Werror=switch]
    switch (objp->op) {

To avoid this, change rxgen to always generate a 'default' arm in the
generated switch if there's one specified in the RPC-L. For a void
default, just generate an empty default arm, which avoids the compiler
warning.

Change-Id: I6ac457a4669439ef896b9cad6eb7de2f03068b69
Reviewed-on: https://gerrit.openafs.org/14798
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/rxgen/rpc_cout.c

index 5c17a90..70bbd67 100644 (file)
@@ -363,8 +363,8 @@ emit_union(definition * def)
     }
     dflt = def->def.un.default_decl;
     if (dflt != NULL) {
+       f_print(fout, "\tdefault:\n");
        if (!streq(dflt->type, "void")) {
-           f_print(fout, "\tdefault:\n");
            object =
                alloc(strlen(def->def_name) + strlen(format) +
                      strlen(dflt->name) + 1);
@@ -375,8 +375,8 @@ emit_union(definition * def)
            print_ifstat(2, dflt->prefix, dflt->type, dflt->rel,
                         dflt->array_max, object, dflt->name);
            free(object);
-           f_print(fout, "\t\tbreak;\n");
        }
+       f_print(fout, "\t\tbreak;\n");
     } else {
        f_print(fout, "\tdefault:\n");
        f_print(fout, "\t\treturn (FALSE);\n");