aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cparser/Diagnostics.ml5
-rw-r--r--cparser/Diagnostics.mli1
-rw-r--r--cparser/Elab.ml9
3 files changed, 11 insertions, 4 deletions
diff --git a/cparser/Diagnostics.ml b/cparser/Diagnostics.ml
index 52e5e456..0987068e 100644
--- a/cparser/Diagnostics.ml
+++ b/cparser/Diagnostics.ml
@@ -96,6 +96,7 @@ type warning_type =
| Extern_after_definition
| Static_in_inline
| Flexible_array_extensions
+ | Tentative_incomplete_static
(* List of active warnings *)
let active_warnings: warning_type list ref = ref [
@@ -155,6 +156,7 @@ let string_of_warning = function
| Extern_after_definition -> "extern-after-definition"
| Static_in_inline -> "static-in-inline"
| Flexible_array_extensions -> "flexible-array-extensions"
+ | Tentative_incomplete_static -> "tentative-incomplete-static"
(* Activate the given warning *)
let activate_warning w () =
@@ -206,6 +208,7 @@ let wall () =
Extern_after_definition;
Static_in_inline;
Flexible_array_extensions;
+ Tentative_incomplete_static;
]
let wnothing () =
@@ -241,6 +244,7 @@ let werror () =
Extern_after_definition;
Static_in_inline;
Flexible_array_extensions;
+ Tentative_incomplete_static;
]
(* Generate the warning key for the message *)
@@ -423,6 +427,7 @@ let warning_options =
error_option Extern_after_definition @
error_option Static_in_inline @
error_option Flexible_array_extensions @
+ error_option Tentative_incomplete_static @
[Exact ("-Wfatal-errors"), Set error_fatal;
Exact ("-fdiagnostics-color"), Ignore; (* Either output supports it or no color *)
Exact ("-fno-diagnostics-color"), Unset color_diagnostics;
diff --git a/cparser/Diagnostics.mli b/cparser/Diagnostics.mli
index 62c54314..2a3643d5 100644
--- a/cparser/Diagnostics.mli
+++ b/cparser/Diagnostics.mli
@@ -53,6 +53,7 @@ type warning_type =
| Extern_after_definition (** extern declaration after non-extern definition *)
| Static_in_inline (** static variable in non-static inline function *)
| Flexible_array_extensions (** usange of structs with flexible arrays in structs and arrays *)
+ | Tentative_incomplete_static (** static tentative definition with incomplete type *)
val warning : (string * int) -> warning_type -> ('a, Format.formatter, unit, unit, unit, unit) format6 -> 'a
(** [warning (f,c) w fmt arg1 ... argN] formats the arguments [arg1] to [argN] as warining according to
diff --git a/cparser/Elab.ml b/cparser/Elab.ml
index 46861708..cc7648e0 100644
--- a/cparser/Elab.ml
+++ b/cparser/Elab.ml
@@ -2354,10 +2354,11 @@ let enter_decdefs local nonstatic_inline loc env sto dl =
(* update environment with refined type *)
let env2 = Env.add_ident env1 id sto' ty' in
(* check for incomplete type *)
- if local && sto' <> Storage_extern
- && not isfun
- && wrap incomplete_type loc env ty' then
- error loc "variable has incomplete type %a" (print_typ env) ty';
+ if not isfun && wrap incomplete_type loc env ty' then
+ if not local && sto' = Storage_static then begin
+ warning loc Tentative_incomplete_static "tentative static definition with incomplete type";
+ end else if local && sto' <> Storage_extern then
+ error loc "variable has incomplete type %a" (print_typ env) ty';
(* check for static variables in nonstatic inline functions *)
if local && nonstatic_inline
&& sto' = Storage_static