From 7d91167706b72103ddf9f4088cf02dd9761fdf47 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Wed, 25 Apr 2018 19:14:41 +0200 Subject: Check for enums that have the same tag as composites (#100) Enum tags, struct tags and union tags share a common namespace, thus having an enum with the same tag as a struct or union is not allowed. Bug 23548 --- cparser/Elab.ml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'cparser/Elab.ml') diff --git a/cparser/Elab.ml b/cparser/Elab.ml index 54021ee4..55764c3c 100644 --- a/cparser/Elab.ml +++ b/cparser/Elab.ml @@ -931,6 +931,8 @@ and elab_struct_or_union keep_ty only kind loc tag optmembers attrs env = match tag with | None -> None, "" | Some s -> + if redef Env.lookup_enum env s then + error loc "'%s' redeclared as different kind of symbol" s; Env.lookup_composite env s, s in match optbinding, optmembers with @@ -1011,7 +1013,12 @@ and elab_enum_item env ((s, exp), loc) nextval = (* Elaboration of an enumeration declaration. C99 section 6.7.2.2 *) and elab_enum only loc tag optmembers attrs env = - let tag = match tag with None -> "" | Some s -> s in + let tag = match tag with + | None -> "" + | Some s -> + if redef Env.lookup_struct env s || redef Env.lookup_union env s then + error loc "'%s' redeclared as different kind of symbol" s; + s in match optmembers with | None -> if only && not (redef Env.lookup_enum env tag) then -- cgit