aboutsummaryrefslogtreecommitdiffstats
path: root/cparser/Elab.ml
diff options
context:
space:
mode:
authorBernhard Schommer <bschommer@users.noreply.github.com>2018-04-25 19:14:41 +0200
committerXavier Leroy <xavierleroy@users.noreply.github.com>2018-04-25 19:14:41 +0200
commit7d91167706b72103ddf9f4088cf02dd9761fdf47 (patch)
tree09e1f0518b66217de370c6c4119b66f35aedca99 /cparser/Elab.ml
parent3b6a054a9a2f54e9c351a4d343331499453c39c5 (diff)
downloadcompcert-kvx-7d91167706b72103ddf9f4088cf02dd9761fdf47.tar.gz
compcert-kvx-7d91167706b72103ddf9f4088cf02dd9761fdf47.zip
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
Diffstat (limited to 'cparser/Elab.ml')
-rw-r--r--cparser/Elab.ml9
1 files changed, 8 insertions, 1 deletions
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