Skip to content

Commit d8822cc

Browse files
Fix double add_identifier: skip re-registration in doDeclaration for initialized declarators
Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
1 parent f9a7b12 commit d8822cc

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/frontc/cparser.mly

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,15 @@ let doDeclaration (loc: cabsloc) (specs: spec_elem list) (nl: init_name list) :
123123
if nl = [] then
124124
ONLYTYPEDEF (specs, loc)
125125
else begin
126-
(* Tell the lexer about the new variable names *)
127-
List.iter (fun ((n, _, _, _), _) -> !Lexerhack.add_identifier n) nl;
126+
(* Tell the lexer about the new variable names.
127+
For initialized declarations, add_identifier was already called in
128+
declarator_init_start before the initializer was parsed (C11 6.2.1.7).
129+
Only register names that have no initializer here. *)
130+
List.iter (fun ((n, _, _, _), init) ->
131+
match init with
132+
| NO_INIT -> !Lexerhack.add_identifier n
133+
| _ -> ()
134+
) nl;
128135
DECDEF ((specs, nl), loc)
129136
end
130137

0 commit comments

Comments
 (0)