From 940ebe1a61a4e2ce9a564520339f6499a767dcc8 Mon Sep 17 00:00:00 2001 From: xleroy Date: Sun, 17 Aug 2014 12:06:47 +0000 Subject: Improve error detection and error messages for enums. git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2568 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- cparser/Elab.ml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cparser/Elab.ml b/cparser/Elab.ml index f6ee199..15b749d 100644 --- a/cparser/Elab.ml +++ b/cparser/Elab.ml @@ -474,7 +474,7 @@ let rec elab_specifier ?(only = false) loc env specifier = let a' = add_attributes (get_type_attrs()) (elab_attributes env a) in let (id', env') = - elab_enum loc id optmembers a' env in + elab_enum only loc id optmembers a' env in (!sto, !inline, !typedef, TEnum(id', !attr), env') (* Specifier doesn't make sense *) @@ -756,13 +756,17 @@ and elab_enum_item env ((s, exp), loc) nextval = (* Elaboration of an enumeration declaration. C99 section 6.7.2.2 *) -and elab_enum loc tag optmembers attrs env = +and elab_enum only loc tag optmembers attrs env = let tag = match tag with None -> "" | Some s -> s in match optmembers with | None -> + if only then + fatal_error loc + "forward declaration of 'enum %s' is not allowed in ISO C" tag; let (tag', info) = wrap Env.lookup_enum loc env tag in (tag', env) - (* XXX this will cause an error for incomplete enum definitions. *) | Some members -> + if tag <> "" && redef Env.lookup_enum env tag then + error loc "redefinition of 'enum %s'" tag; let rec elab_members env nextval = function | [] -> ([], env) | hd :: tl -> -- cgit v1.2.3