Skip to content
Snippets Groups Projects
Commit 9661df55 authored by Virgile Prevosto's avatar Virgile Prevosto
Browse files

[cparser] accept anonymous typedefs again albeit with a warning

It appears that old parser accepted something like

```
typedef enum foo { A, B, C };
```

previous commit forgot to reset the Lexerhack's typedef status after such
a declaration, resulting in considering the _next_ declaration a typedef
as well, provoking completely inaccurate errors afterwards. We now accept
such programs, but, like clang, we emit a warning about such typedef.
parent adafa2d0
No related branches found
No related tags found
No related merge requests found
...@@ -1077,11 +1077,28 @@ declaration: /* ISO 6.7.*/ ...@@ -1077,11 +1077,28 @@ declaration: /* ISO 6.7.*/
decl_spec_list init_declarator_list SEMICOLON decl_spec_list init_declarator_list SEMICOLON
{ doDeclaration None ((snd $1)) (fst $1) $2 } { doDeclaration None ((snd $1)) (fst $1) $2 }
| decl_spec_list SEMICOLON | decl_spec_list SEMICOLON
{ doDeclaration None ((snd $1)) (fst $1) [] } { if !Lexerhack.is_typedef () then begin
let source =
Cil_datatype.Position.of_lexing_pos $startpos($1)
in
Kernel.warning ~source ~wkey:Kernel.wkey_unnamed_typedef
"typedef without a name"
end;
!Lexerhack.reset_typedef();
doDeclaration None ((snd $1)) (fst $1) []
}
| SPEC decl_spec_list init_declarator_list SEMICOLON | SPEC decl_spec_list init_declarator_list SEMICOLON
{ doDeclaration (Some $1) ((snd $2)) (fst $2) $3 } { doDeclaration (Some $1) ((snd $2)) (fst $2) $3 }
| SPEC decl_spec_list SEMICOLON | SPEC decl_spec_list SEMICOLON
{ doDeclaration (Some $1) ((snd $2)) (fst $2) [] } { if !Lexerhack.is_typedef () then begin
let source =
Cil_datatype.Position.of_lexing_pos $startpos($2)
in
Kernel.warning ~source ~wkey:Kernel.wkey_unnamed_typedef
"typedef without a name"
end;
!Lexerhack.reset_typedef();
doDeclaration (Some $1) ((snd $2)) (fst $2) [] }
| static_assert_declaration | static_assert_declaration
{ let (e, m, loc) = $1 in STATIC_ASSERT (e, m, loc) } { let (e, m, loc) = $1 in STATIC_ASSERT (e, m, loc) }
; ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment