-- Number of warnings changed into errors as a result of matching a pattern
-- given in a Warning_As_Error configuration pragma.
- Compile_Time_Pragma_Warnings : Nat := 0;
- -- Number of warnings that come from a Compile_Time_Warning pragma
-
Configurable_Run_Time_Violations : Nat := 0;
-- Count of configurable run time violations so far. This is used to
-- suppress certain cascaded error messages when we know that we may not
Line => Get_Physical_Line_Number (Sptr),
Col => Get_Column_Number (Sptr),
Compile_Time_Pragma => Is_Compile_Time_Msg,
- Warn_Err => False, -- reset below
+ Warn_Err => None, -- reset below
Warn_Chr => Warning_Msg_Char,
Uncond => Is_Unconditional_Msg,
Msg_Cont => Continuation,
Fixes => First_Fix));
Cur_Msg := Errors.Last;
- -- Test if warning to be treated as error
-
- Errors.Table (Cur_Msg).Warn_Err :=
- Error_Msg_Kind in Warning | Style
- and then (Warning_Treated_As_Error (Errors.Table (Cur_Msg))
- or else Is_Runtime_Raise);
+ -- Test if a warning is to be treated as error:
+ -- * It is marked by a pragma Warning_As_Error
+ -- * Warning_Mode is Treat_Run_Time_Warnings_As_Errors and we are
+ -- dealing with a runtime warning.
+ -- * Warning_Mode is Warnings_As_Errors and it is not a compile time
+ -- message.
+
+ if Error_Msg_Kind in Warning | Style then
+ if Warning_Treated_As_Error (Errors.Table (Cur_Msg)) then
+ Errors.Table (Cur_Msg).Warn_Err := From_Pragma;
+ elsif Warning_Mode = Treat_Run_Time_Warnings_As_Errors
+ and then Is_Runtime_Raise_Msg
+ then
+ Errors.Table (Cur_Msg).Warn_Err := From_Run_Time_As_Err;
+ elsif Warning_Mode = Treat_As_Error and then not Is_Compile_Time_Msg
+ then
+ Errors.Table (Cur_Msg).Warn_Err := From_Warn_As_Err;
+ end if;
+ end if;
-- If immediate errors mode set, output error message now. Also output
-- now if the -d1 debug flag is set (so node number message comes out
Warnings_Treated_As_Errors := 0;
Warnings_Detected := 0;
Warnings_As_Errors_Count := 0;
- Compile_Time_Pragma_Warnings := 0;
-- Initialize warnings tables
Write_Str ("{""kind"":");
- if Errors.Table (E).Kind = Warning and then not Errors.Table (E).Warn_Err
+ if Errors.Table (E).Kind = Warning
+ and then Errors.Table (E).Warn_Err = None
then
Write_Str ("""warning""");
elsif Errors.Table (E).Kind in
end if;
if Warning_Mode = Treat_As_Error then
+ pragma Assert (Warnings_Detected >= Warnings_Treated_As_Errors);
Total_Errors_Detected :=
- Total_Errors_Detected
- + Warnings_Detected
- - Compile_Time_Pragma_Warnings;
- Warnings_Detected := Compile_Time_Pragma_Warnings;
+ Total_Errors_Detected + Warnings_Treated_As_Errors;
+ Warnings_Detected := Warnings_Detected - Warnings_Treated_As_Errors;
end if;
end Output_Messages;
Set_Msg_Insertion_Code;
else
- -- Switch the message from a warning to an error if the flag
- -- -gnatwE is specified to treat run-time exception warnings
- -- as non-serious errors.
-
- if Error_Msg_Kind = Warning
- and then Warning_Mode = Treat_Run_Time_Warnings_As_Errors
- then
- Is_Runtime_Raise := True;
- end if;
+ Is_Runtime_Raise_Msg := True;
if Error_Msg_Kind = Warning then
Set_Msg_Str ("will be raised at run time");
Write_Str (" " & Switch_Str);
end if;
- if E_Msg.Warn_Err then
- Write_Str (" [warning-as-error]");
+ if E_Msg.Warn_Err = From_Pragma then
+ Write_Str (" " & Warn_As_Err_Tag);
end if;
Write_Eol;
------------------------
function Compilation_Errors return Boolean is
- Warnings_Count : constant Int := Warnings_Detected;
begin
- if Total_Errors_Detected /= 0 then
- return True;
-
- elsif Warnings_Treated_As_Errors /= 0 then
- return True;
-
- -- We should never treat warnings that originate from a
- -- Compile_Time_Warning pragma as an error. Warnings_Count is the sum
- -- of both "normal" and Compile_Time_Warning warnings. This means that
- -- there are only one or more non-Compile_Time_Warning warnings when
- -- Warnings_Count is greater than Compile_Time_Pragma_Warnings.
-
- elsif Warning_Mode = Treat_As_Error
- and then Warnings_Count > Compile_Time_Pragma_Warnings
- then
- return True;
- end if;
-
- return False;
+ return Total_Errors_Detected /= 0
+ or else Warnings_Treated_As_Errors /= 0;
end Compilation_Errors;
------------------------------
when Warning | Style =>
Warnings_Detected := Warnings_Detected - 1;
- if E.Warn_Err then
+ if E.Warn_Err /= None then
Warnings_Treated_As_Errors := Warnings_Treated_As_Errors - 1;
end if;
- if E.Compile_Time_Pragma then
- Compile_Time_Pragma_Warnings :=
- Compile_Time_Pragma_Warnings - 1;
- end if;
-
when High_Check | Medium_Check | Low_Check =>
Check_Messages := Check_Messages - 1;
w (" Line = ", Int (E.Line));
w (" Col = ", Int (E.Col));
w (" Kind = ", E.Kind'Img);
- w (" Warn_Err = ", E.Warn_Err);
+ w (" Warn_Err = ", E.Warn_Err'Img);
w (" Warn_Chr = '" & E.Warn_Chr & ''');
w (" Uncond = ", E.Uncond);
w (" Msg_Cont = ", E.Msg_Cont);
when Warning | Style =>
Warnings_Detected := Warnings_Detected + 1;
- if E.Warn_Err then
+ if E.Warn_Err /= None then
Warnings_Treated_As_Errors := Warnings_Treated_As_Errors + 1;
-- Propagate Warn_Err to all of the preceeding continuation
-- messages and the main message.
for J in reverse 1 .. Errors.Last loop
- if not Errors.Table (J).Warn_Err then
+ if Errors.Table (J).Warn_Err = None then
Errors.Table (J).Warn_Err := E.Warn_Err;
Warnings_Treated_As_Errors :=
end loop;
end if;
- if E.Compile_Time_Pragma then
- Compile_Time_Pragma_Warnings :=
- Compile_Time_Pragma_Warnings + 1;
- end if;
-
when High_Check | Medium_Check | Low_Check =>
Check_Messages := Check_Messages + 1;
-- Prefix with "error:" rather than warning.
-- Additionally include the style suffix when needed.
- if E_Msg.Warn_Err then
+ if E_Msg.Warn_Err in From_Pragma | From_Run_Time_As_Err then
Append
(Buf,
SGR_Error & "error: " & SGR_Reset &
-- Postfix [warning-as-error] at the end
- if E_Msg.Warn_Err then
- Append (Buf, " [warning-as-error]");
+ if E_Msg.Warn_Err = From_Pragma then
+ Append (Buf, " " & Warn_As_Err_Tag);
end if;
Output_Text_Within (To_String (Buf), Line_Length);
Error_Msg_Kind := Error;
Is_Unconditional_Msg := False;
- Is_Runtime_Raise := False;
+ Is_Runtime_Raise_Msg := False;
Warning_Msg_Char := " ";
-- Check style message
Write_Str (" errors");
end if;
- -- We now need to output warnings. When using -gnatwe, all warnings
- -- should be treated as errors, except for warnings originating from
- -- the use of the Compile_Time_Warning pragma. Another situation
- -- where a warning might be treated as an error is when the source
- -- code contains a Warning_As_Error pragma.
- -- When warnings are treated as errors, we still log them as
- -- warnings, but we add a message denoting how many of these warnings
- -- are also errors.
-
- declare
- Warnings_Count : constant Int := Warnings_Detected;
+ if Warnings_Detected > 0 then
+ Write_Str (", ");
+ Write_Int (Warnings_Detected);
+ Write_Str (" warning");
- Non_Compile_Time_Warnings : Int;
- -- Number of warnings that do not come from a Compile_Time_Warning
- -- pragmas.
+ if Warnings_Detected > 1 then
+ Write_Char ('s');
+ end if;
- begin
- if Warnings_Count > 0 then
- Write_Str (", ");
- Write_Int (Warnings_Count);
- Write_Str (" warning");
+ if Warnings_Treated_As_Errors > 0 then
+ Write_Str (" (");
- if Warnings_Count > 1 then
- Write_Char ('s');
+ if Warnings_Treated_As_Errors /= Warnings_Detected then
+ Write_Int (Warnings_Treated_As_Errors);
+ Write_Str (" ");
end if;
- Non_Compile_Time_Warnings :=
- Warnings_Count - Compile_Time_Pragma_Warnings;
+ Write_Str ("treated as error");
- if Warning_Mode = Treat_As_Error
- and then Non_Compile_Time_Warnings > 0
- then
- Write_Str (" (");
-
- if Compile_Time_Pragma_Warnings > 0 then
- Write_Int (Non_Compile_Time_Warnings);
- Write_Str (" ");
- end if;
-
- Write_Str ("treated as error");
-
- if Non_Compile_Time_Warnings > 1 then
- Write_Char ('s');
- end if;
-
- Write_Char (')');
-
- elsif Warnings_Treated_As_Errors > 0 then
- Write_Str (" (");
-
- if Warnings_Treated_As_Errors /= Warnings_Count then
- Write_Int (Warnings_Treated_As_Errors);
- Write_Str (" ");
- end if;
-
- Write_Str ("treated as error");
-
- if Warnings_Treated_As_Errors > 1 then
- Write_Str ("s");
- end if;
-
- Write_Str (")");
+ if Warnings_Treated_As_Errors > 1 then
+ Write_Str ("s");
end if;
+
+ Write_Str (")");
end if;
- end;
+ end if;
if Info_Messages /= 0 then
Write_Str (", ");
-- Set true to indicate that the current message originates from a
-- Compile_Time_Warning or Compile_Time_Error pragma.
+ Is_Runtime_Raise_Msg : Boolean := False;
+ -- Set to True to indicate that the current message is a constraint error
+ -- that will be raised at runtime (contains [).
+
Is_Unconditional_Msg : Boolean := False;
-- Set True to indicate that the current message contains the insertion
-- character ! and is thus to be treated as an unconditional message.
- Is_Runtime_Raise : Boolean := False;
- -- Set to True to indicate that the current message is a warning about a
- -- constraint error that will be raised at runtime (contains [ and switch
- -- -gnatwE was given)..
-
Error_Msg_Kind : Error_Msg_Type := Error;
Warning_Msg_Char : String (1 .. 2);
Table_Increment => 200,
Table_Name => "Fix");
+ type Warning_As_Error_Kind is
+ (None, From_Pragma, From_Warn_As_Err, From_Run_Time_As_Err);
+ -- The reason for a warning to be converted as an error:
+ -- * None - Regular warning. Default value for non-warning messages.
+ -- * From_Pragma - Warning converted to an error due to a pragma
+ -- Warning_As_Error.
+ -- * From_Warn_As_Err - Warning converted to an error because the
+ -- Warning_Mode was set to Treat_As_Errors by -gnatwe.
+ -- * From_Run_Time_As_Err - Warning converted to an error because the
+ -- Warning_Mode was set to Treat_Run_Time_Warnings_As_Errors by -gnatwE.
+
type Error_Msg_Object is record
Text : String_Ptr;
-- Text of error message, fully expanded with all insertions
-- True if the message originates from a Compile_Time_Warning or
-- Compile_Time_Error pragma
- Warn_Err : Boolean;
- -- True if this is a warning message which is to be treated as an error
- -- as a result of a match with a Warning_As_Error pragma.
+ Warn_Err : Warning_As_Error_Kind;
+ -- By default this is None. If the warning was converted by some reason
+ -- to an error then it has a different value. Depending on the value
+ -- the warning will be printed in a different way due to historical
+ -- reasons.
Warn_Chr : String (1 .. 2);
-- See Warning_Msg_Char
-- Update E to point to the next continuation message
function Kind_To_String (E : Error_Msg_Object) return String is
- (if E.Warn_Err then "error"
+ (if E.Warn_Err in From_Pragma | From_Run_Time_As_Err then "error"
else
(case E.Kind is
when Error | Non_Serious_Error => "error",
(SGR_Seq (Color_Bold));
function Get_SGR_Code (E_Msg : Error_Msg_Object) return String is
- (if E_Msg.Warn_Err then SGR_Error
+ (if E_Msg.Warn_Err /= None then SGR_Error
else
(case E_Msg.Kind is
when Warning | Style => SGR_Warning,
-- buffer, and preceded by a space.
function Compilation_Errors return Boolean;
- -- Returns true if errors have been detected, or warnings in -gnatwe
- -- (treat warnings as errors) mode.
+ -- Returns true if errors have been detected, or warnings that are treated
+ -- as errors.
procedure dmsg (Id : Error_Msg_Id);
-- Debugging routine to dump an error message
High_Prefix : constant String := "high: ";
Style_Prefix : constant String := "(style) ";
+ Warn_As_Err_Tag : constant String := "[warning-as-error]";
+ -- Tag used at the end of warning messages that were converted by
+ -- pragma Warning_As_Error.
+
procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr);
-- All error messages whose location is in the range From .. To (not
-- including the end points) will be deleted from the error listing.
Line => Get_Physical_Line_Number (Sptr),
Col => Get_Column_Number (Sptr),
Compile_Time_Pragma => Is_Compile_Time_Msg,
- Warn_Err => Warning_Mode = Treat_As_Error,
+ Warn_Err => (if Warning_Mode = Treat_As_Error
+ then From_Warn_As_Err
+ else None),
Warn_Chr => Warning_Msg_Char,
Uncond => Is_Unconditional_Msg,
Msg_Cont => Continuation,