https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70073

            Bug ID: 70073
           Summary: -Werror=return-type ignores call to function with
                    attribute noreturn
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: douglas.bagnall at catalyst dot net.nz
  Target Milestone: ---

GCC 6 (or more precisely, "git-svn-id:
svn+ssh://gcc.gnu.org/svn/gcc/trunk@233864
138bc75d-0d04-0410-961f-82ee72b054a4"), fails to compile Samba with -Werror,
with this message:

../source4/heimdal/lib/hx509/sel.c: In function ‘_hx509_expr_eval’:
../source4/heimdal/lib/hx509/sel.c:180:1: error: control reaches end of
non-void function [-Werror=return-type]
 }
 ^

I have failed to make a minimal testcase,  but this is what is happening. In
headers:


#define UNREACHABLE(x)

void
_hx509_abort (
        const char */*fmt*/,
        ...)
     __attribute__ ((noreturn, format (printf, 1, 2)));



and the default case in this function triggers the error:


int
_hx509_expr_eval(hx509_context context, hx509_env env, struct hx_expr *expr)
{
    switch (expr->op) {
    case op_TRUE:
        return 1;
    case op_FALSE:
        return 0;
    case op_NOT:
        return ! _hx509_expr_eval(context, env, expr->arg1);
    case op_AND:
        return _hx509_expr_eval(context, env, expr->arg1) &&
            _hx509_expr_eval(context, env, expr->arg2);
    case op_OR:
        return _hx509_expr_eval(context, env, expr->arg1) ||
            _hx509_expr_eval(context, env, expr->arg2);
    case op_COMP:
        return eval_comp(context, env, expr->arg1);
    default:
        _hx509_abort("hx509 eval expr with unknown op: %d", (int)expr->op);
        UNREACHABLE(return 0);
    }
}


As you can see, cpp converts the "UNREACHABLE(return 0)" to nothing, but GCC
fails to notice that _hx509_abort() does not return. 

Previous versions of GCC have compiled this without trouble.

Reply via email to