diff options
author | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2014-08-17 12:06:47 +0000 |
---|---|---|
committer | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2014-08-17 12:06:47 +0000 |
commit | 940ebe1a61a4e2ce9a564520339f6499a767dcc8 (patch) | |
tree | 0a1ecad340f81fbc19c81d3d8f938742b0a2824d /cparser | |
parent | 0e4def2853d5cfa9034344a5c4570543ed271ee2 (diff) |
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
Diffstat (limited to 'cparser')
-rw-r--r-- | cparser/Elab.ml | 10 |
1 files 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 -> |