@@ -2667,6 +2667,7 @@ let rec doSpecList (suggestedAnonName: string) (* This string will be part of
26672667 if n = " " then E. s (error " Missing struct tag on incomplete struct" );
26682668 findCompType " struct" n []
26692669 | [A. Tstruct (n, Some nglist, extraAttrs)] -> (* A definition of a struct *)
2670+ let nglist = doStructDecls nglist in
26702671 let (specs, names) = List. split nglist in
26712672 let n' =
26722673 if n <> " " then n else anonStructName " struct" suggestedAnonName specs in
@@ -2678,6 +2679,7 @@ let rec doSpecList (suggestedAnonName: string) (* This string will be part of
26782679 if n = " " then E. s (error " Missing union tag on incomplete union" );
26792680 findCompType " union" n []
26802681 | [A. Tunion (n, Some nglist, extraAttrs)] -> (* A definition of a union *)
2682+ let nglist = doStructDecls nglist in
26812683 let (specs, names) = List. split nglist in
26822684 let n' =
26832685 if n <> " " then n else anonStructName " union" suggestedAnonName specs in
@@ -2827,6 +2829,23 @@ let rec doSpecList (suggestedAnonName: string) (* This string will be part of
28272829 in
28282830 bt,! storage,! isinline,List. rev (! attrs @ (convertCVtoAttr ! cvattrs))
28292831
2832+
2833+ and doStructDecls (struct_decls : struct_decl list ): field_group list =
2834+ List. filter_map (function
2835+ | FIELD_GROUP fg -> Some fg
2836+ | FIELD_STATIC_ASSERT (e , str , loc ) ->
2837+ let loc = convLoc loc in
2838+ let d_message () = function
2839+ | None -> nil
2840+ | Some str -> dprintf " : %s" str
2841+ in
2842+ begin match isIntegerConstant e with
2843+ | Some 0 -> E. s (error " Static assert failed at %a%a" d_loc loc d_message str)
2844+ | Some _ -> None
2845+ | None -> E. s (error " Static assert with a non-constant at %a%a" d_loc loc d_message str)
2846+ end
2847+ ) struct_decls
2848+
28302849(* given some cv attributes, convert them into named attributes for
28312850 uniform processing *)
28322851and convertCVtoAttr (src : A.cvspec list ) : A.attribute list =
@@ -6624,7 +6643,19 @@ and doDecl (isglobal: bool) (isstmt: bool) : A.definition -> chunk = function
66246643 E. s (bug " doDecl returns non-empty statement for global" ))
66256644 dl;
66266645 empty
6627- | STATIC_ASSERT _ -> empty
6646+ | STATIC_ASSERT (e , str , loc ) ->
6647+ if isglobal || isstmt then
6648+ currentLoc := convLoc loc;
6649+ currentExpLoc := convLoc loc;
6650+ let d_message () = function
6651+ | None -> nil
6652+ | Some str -> dprintf " : %s" str
6653+ in
6654+ begin match isIntegerConstant e with
6655+ | Some 0 -> E. s (error " Static assert failed at %a%a" d_loc ! currentLoc d_message str)
6656+ | Some _ -> empty
6657+ | None -> E. s (error " Static assert with a non-constant at %a%a" d_loc ! currentLoc d_message str)
6658+ end
66286659 | _ -> E. s (error " unexpected form of declaration" )
66296660
66306661and doTypedef ((specs , nl ): A. name_group ) =
0 commit comments