1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1999-2019, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Err_Vars; use Err_Vars;
28 with Output; use Output;
30 package body Warnsw is
34 procedure All_Warnings (Setting : Boolean);
35 -- Sets all warnings off if Setting = False, and on if Setting = True
37 procedure WA_Warnings;
38 -- Turn on all warnings set by -gnatwa (also used by -gnatw.g)
44 procedure All_Warnings (Setting : Boolean) is
46 Address_Clause_Overlay_Warnings := Setting;
47 Check_Unreferenced := Setting;
48 Check_Unreferenced_Formals := Setting;
49 Check_Withs := Setting;
50 Constant_Condition_Warnings := Setting;
51 Elab_Warnings := Setting;
52 Implementation_Unit_Warnings := Setting;
53 Ineffective_Inline_Warnings := Setting;
54 List_Body_Required_Info := Setting;
55 List_Inherited_Aspects := Setting;
56 Warn_On_Ada_2005_Compatibility := Setting;
57 Warn_On_Ada_2012_Compatibility := Setting;
58 Warn_On_All_Unread_Out_Parameters := Setting;
59 Warn_On_Anonymous_Allocators := Setting;
60 Warn_On_Assertion_Failure := Setting;
61 Warn_On_Assumed_Low_Bound := Setting;
62 Warn_On_Atomic_Synchronization := Setting;
63 Warn_On_Bad_Fixed_Value := Setting;
64 Warn_On_Biased_Representation := Setting;
65 Warn_On_Constant := Setting;
66 Warn_On_Deleted_Code := Setting;
67 Warn_On_Dereference := Setting;
68 Warn_On_Export_Import := Setting;
69 Warn_On_Hiding := Setting;
70 Warn_On_Late_Primitives := Setting;
71 Warn_On_Modified_Unread := Setting;
72 Warn_On_No_Value_Assigned := Setting;
73 Warn_On_Non_Local_Exception := Setting;
74 Warn_On_Object_Renames_Function := Setting;
75 Warn_On_Obsolescent_Feature := Setting;
76 Warn_On_Overlap := Setting;
77 Warn_On_Overridden_Size := Setting;
78 Warn_On_Parameter_Order := Setting;
79 Warn_On_Questionable_Layout := Setting;
80 Warn_On_Questionable_Missing_Parens := Setting;
81 Warn_On_Record_Holes := Setting;
82 Warn_On_Component_Order := Setting;
83 Warn_On_Redundant_Constructs := Setting;
84 Warn_On_Reverse_Bit_Order := Setting;
85 Warn_On_Size_Alignment := Setting;
86 Warn_On_Standard_Redefinition := Setting;
87 Warn_On_Suspicious_Contract := Setting;
88 Warn_On_Suspicious_Modulus_Value := Setting;
89 Warn_On_Unchecked_Conversion := Setting;
90 Warn_On_Unknown_Compile_Time_Warning := Setting;
91 Warn_On_Unordered_Enumeration_Type := Setting;
92 Warn_On_Unrecognized_Pragma := Setting;
93 Warn_On_Unrepped_Components := Setting;
94 Warn_On_Warnings_Off := Setting;
97 ----------------------
98 -- Restore_Warnings --
99 ----------------------
101 procedure Restore_Warnings (W : Warning_Record) is
103 Address_Clause_Overlay_Warnings :=
104 W.Address_Clause_Overlay_Warnings;
105 Check_Unreferenced :=
106 W.Check_Unreferenced;
107 Check_Unreferenced_Formals :=
108 W.Check_Unreferenced_Formals;
111 Constant_Condition_Warnings :=
112 W.Constant_Condition_Warnings;
115 Elab_Info_Messages :=
116 W.Elab_Info_Messages;
117 Implementation_Unit_Warnings :=
118 W.Implementation_Unit_Warnings;
119 Ineffective_Inline_Warnings :=
120 W.Ineffective_Inline_Warnings;
121 List_Body_Required_Info :=
122 W.List_Body_Required_Info;
123 List_Inherited_Aspects :=
124 W.List_Inherited_Aspects;
125 No_Warn_On_Non_Local_Exception :=
126 W.No_Warn_On_Non_Local_Exception;
127 Warning_Doc_Switch :=
128 W.Warning_Doc_Switch;
129 Warn_On_Ada_2005_Compatibility :=
130 W.Warn_On_Ada_2005_Compatibility;
131 Warn_On_Ada_2012_Compatibility :=
132 W.Warn_On_Ada_2012_Compatibility;
133 Warn_On_All_Unread_Out_Parameters :=
134 W.Warn_On_All_Unread_Out_Parameters;
135 Warn_On_Anonymous_Allocators :=
136 W.Warn_On_Anonymous_Allocators;
137 Warn_On_Assertion_Failure :=
138 W.Warn_On_Assertion_Failure;
139 Warn_On_Assumed_Low_Bound :=
140 W.Warn_On_Assumed_Low_Bound;
141 Warn_On_Atomic_Synchronization :=
142 W.Warn_On_Atomic_Synchronization;
143 Warn_On_Bad_Fixed_Value :=
144 W.Warn_On_Bad_Fixed_Value;
145 Warn_On_Biased_Representation :=
146 W.Warn_On_Biased_Representation;
149 Warn_On_Deleted_Code :=
150 W.Warn_On_Deleted_Code;
151 Warn_On_Dereference :=
152 W.Warn_On_Dereference;
153 Warn_On_Export_Import :=
154 W.Warn_On_Export_Import;
157 Warn_On_Late_Primitives :=
158 W.Warn_On_Late_Primitives;
159 Warn_On_Modified_Unread :=
160 W.Warn_On_Modified_Unread;
161 Warn_On_No_Value_Assigned :=
162 W.Warn_On_No_Value_Assigned;
163 Warn_On_Non_Local_Exception :=
164 W.Warn_On_Non_Local_Exception;
165 Warn_On_Object_Renames_Function :=
166 W.Warn_On_Object_Renames_Function;
167 Warn_On_Obsolescent_Feature :=
168 W.Warn_On_Obsolescent_Feature;
171 Warn_On_Overridden_Size :=
172 W.Warn_On_Overridden_Size;
173 Warn_On_Parameter_Order :=
174 W.Warn_On_Parameter_Order;
175 Warn_On_Questionable_Layout :=
176 W.Warn_On_Questionable_Layout;
177 Warn_On_Questionable_Missing_Parens :=
178 W.Warn_On_Questionable_Missing_Parens;
179 Warn_On_Record_Holes :=
180 W.Warn_On_Record_Holes;
181 Warn_On_Component_Order :=
182 W.Warn_On_Component_Order;
183 Warn_On_Redundant_Constructs :=
184 W.Warn_On_Redundant_Constructs;
185 Warn_On_Reverse_Bit_Order :=
186 W.Warn_On_Reverse_Bit_Order;
187 Warn_On_Size_Alignment :=
188 W.Warn_On_Size_Alignment;
189 Warn_On_Standard_Redefinition :=
190 W.Warn_On_Standard_Redefinition;
191 Warn_On_Suspicious_Contract :=
192 W.Warn_On_Suspicious_Contract;
193 Warn_On_Unchecked_Conversion :=
194 W.Warn_On_Unchecked_Conversion;
195 Warn_On_Unknown_Compile_Time_Warning :=
196 W.Warn_On_Unknown_Compile_Time_Warning;
197 Warn_On_Unordered_Enumeration_Type :=
198 W.Warn_On_Unordered_Enumeration_Type;
199 Warn_On_Unrecognized_Pragma :=
200 W.Warn_On_Unrecognized_Pragma;
201 Warn_On_Unrepped_Components :=
202 W.Warn_On_Unrepped_Components;
203 Warn_On_Warnings_Off :=
204 W.Warn_On_Warnings_Off;
205 end Restore_Warnings;
211 function Save_Warnings return Warning_Record is
215 W.Address_Clause_Overlay_Warnings :=
216 Address_Clause_Overlay_Warnings;
217 W.Check_Unreferenced :=
219 W.Check_Unreferenced_Formals :=
220 Check_Unreferenced_Formals;
223 W.Constant_Condition_Warnings :=
224 Constant_Condition_Warnings;
225 W.Elab_Info_Messages :=
229 W.Implementation_Unit_Warnings :=
230 Implementation_Unit_Warnings;
231 W.Ineffective_Inline_Warnings :=
232 Ineffective_Inline_Warnings;
233 W.List_Body_Required_Info :=
234 List_Body_Required_Info;
235 W.List_Inherited_Aspects :=
236 List_Inherited_Aspects;
237 W.No_Warn_On_Non_Local_Exception :=
238 No_Warn_On_Non_Local_Exception;
239 W.Warning_Doc_Switch :=
241 W.Warn_On_Ada_2005_Compatibility :=
242 Warn_On_Ada_2005_Compatibility;
243 W.Warn_On_Ada_2012_Compatibility :=
244 Warn_On_Ada_2012_Compatibility;
245 W.Warn_On_All_Unread_Out_Parameters :=
246 Warn_On_All_Unread_Out_Parameters;
247 W.Warn_On_Anonymous_Allocators :=
248 Warn_On_Anonymous_Allocators;
249 W.Warn_On_Assertion_Failure :=
250 Warn_On_Assertion_Failure;
251 W.Warn_On_Assumed_Low_Bound :=
252 Warn_On_Assumed_Low_Bound;
253 W.Warn_On_Atomic_Synchronization :=
254 Warn_On_Atomic_Synchronization;
255 W.Warn_On_Bad_Fixed_Value :=
256 Warn_On_Bad_Fixed_Value;
257 W.Warn_On_Biased_Representation :=
258 Warn_On_Biased_Representation;
259 W.Warn_On_Constant :=
261 W.Warn_On_Deleted_Code :=
262 Warn_On_Deleted_Code;
263 W.Warn_On_Dereference :=
265 W.Warn_On_Export_Import :=
266 Warn_On_Export_Import;
269 W.Warn_On_Late_Primitives :=
270 Warn_On_Late_Primitives;
271 W.Warn_On_Modified_Unread :=
272 Warn_On_Modified_Unread;
273 W.Warn_On_No_Value_Assigned :=
274 Warn_On_No_Value_Assigned;
275 W.Warn_On_Non_Local_Exception :=
276 Warn_On_Non_Local_Exception;
277 W.Warn_On_Object_Renames_Function :=
278 Warn_On_Object_Renames_Function;
279 W.Warn_On_Obsolescent_Feature :=
280 Warn_On_Obsolescent_Feature;
283 W.Warn_On_Overridden_Size :=
284 Warn_On_Overridden_Size;
285 W.Warn_On_Parameter_Order :=
286 Warn_On_Parameter_Order;
287 W.Warn_On_Questionable_Layout :=
288 Warn_On_Questionable_Layout;
289 W.Warn_On_Questionable_Missing_Parens :=
290 Warn_On_Questionable_Missing_Parens;
291 W.Warn_On_Record_Holes :=
292 Warn_On_Record_Holes;
293 W.Warn_On_Component_Order :=
294 Warn_On_Component_Order;
295 W.Warn_On_Redundant_Constructs :=
296 Warn_On_Redundant_Constructs;
297 W.Warn_On_Reverse_Bit_Order :=
298 Warn_On_Reverse_Bit_Order;
299 W.Warn_On_Size_Alignment :=
300 Warn_On_Size_Alignment;
301 W.Warn_On_Standard_Redefinition :=
302 Warn_On_Standard_Redefinition;
303 W.Warn_On_Suspicious_Contract :=
304 Warn_On_Suspicious_Contract;
305 W.Warn_On_Unchecked_Conversion :=
306 Warn_On_Unchecked_Conversion;
307 W.Warn_On_Unknown_Compile_Time_Warning :=
308 Warn_On_Unknown_Compile_Time_Warning;
309 W.Warn_On_Unordered_Enumeration_Type :=
310 Warn_On_Unordered_Enumeration_Type;
311 W.Warn_On_Unrecognized_Pragma :=
312 Warn_On_Unrecognized_Pragma;
313 W.Warn_On_Unrepped_Components :=
314 Warn_On_Unrepped_Components;
315 W.Warn_On_Warnings_Off :=
316 Warn_On_Warnings_Off;
320 ----------------------------
321 -- Set_Dot_Warning_Switch --
322 ----------------------------
324 function Set_Dot_Warning_Switch (C : Character) return Boolean is
328 Warn_On_Assertion_Failure := True;
331 Warn_On_Assertion_Failure := False;
334 Warn_On_Biased_Representation := True;
337 Warn_On_Biased_Representation := False;
340 Warn_On_Unrepped_Components := True;
343 Warn_On_Unrepped_Components := False;
346 Warning_Doc_Switch := True;
349 Warning_Doc_Switch := False;
355 Warn_On_Elab_Access := True;
358 Warn_On_Elab_Access := False;
361 Set_GNAT_Mode_Warnings;
364 Warn_On_Record_Holes := True;
367 Warn_On_Record_Holes := False;
370 Warn_On_Overlap := True;
373 Warn_On_Overlap := False;
376 Warn_On_Late_Primitives := True;
379 Warn_On_Late_Primitives := False;
382 Warn_On_Standard_Redefinition := True;
385 Warn_On_Standard_Redefinition := False;
388 List_Inherited_Aspects := True;
391 List_Inherited_Aspects := False;
394 Warn_On_Suspicious_Modulus_Value := True;
397 Warn_On_Suspicious_Modulus_Value := False;
400 Warn_On_Atomic_Synchronization := True;
403 Warn_On_Atomic_Synchronization := False;
406 Warn_On_All_Unread_Out_Parameters := True;
409 Warn_On_All_Unread_Out_Parameters := False;
412 Warn_On_Parameter_Order := True;
415 Warn_On_Parameter_Order := False;
418 Warn_On_Questionable_Layout := True;
421 Warn_On_Questionable_Layout := False;
424 Warn_On_Object_Renames_Function := True;
427 Warn_On_Object_Renames_Function := False;
430 Warn_On_Overridden_Size := True;
433 Warn_On_Overridden_Size := False;
436 Warn_On_Suspicious_Contract := True;
439 Warn_On_Suspicious_Contract := False;
442 Warn_On_Unordered_Enumeration_Type := True;
445 Warn_On_Unordered_Enumeration_Type := False;
448 Warn_On_Reverse_Bit_Order := True;
451 Warn_On_Reverse_Bit_Order := False;
454 Warn_On_Warnings_Off := True;
457 Warn_On_Warnings_Off := False;
460 Warn_On_Non_Local_Exception := True;
463 Warn_On_Non_Local_Exception := False;
464 No_Warn_On_Non_Local_Exception := True;
467 List_Body_Required_Info := True;
470 List_Body_Required_Info := False;
473 Warn_On_Size_Alignment := True;
476 Warn_On_Size_Alignment := False;
479 if Ignore_Unrecognized_VWY_Switches then
480 Write_Line ("unrecognized switch -gnatw." & C & " ignored");
487 end Set_Dot_Warning_Switch;
489 -----------------------------------
490 -- Set_Underscore_Warning_Switch --
491 -----------------------------------
493 function Set_Underscore_Warning_Switch (C : Character) return Boolean is
497 Warn_On_Anonymous_Allocators := True;
500 Warn_On_Anonymous_Allocators := False;
503 Warn_On_Unknown_Compile_Time_Warning := True;
506 Warn_On_Unknown_Compile_Time_Warning := False;
509 Warn_On_Component_Order := True;
512 Warn_On_Component_Order := False;
515 if Ignore_Unrecognized_VWY_Switches then
516 Write_Line ("unrecognized switch -gnatw_" & C & " ignored");
523 end Set_Underscore_Warning_Switch;
525 ----------------------------
526 -- Set_GNAT_Mode_Warnings --
527 ----------------------------
529 procedure Set_GNAT_Mode_Warnings is
531 -- Set -gnatwa warnings and no others
533 All_Warnings (False);
536 -- These warnings are added to the -gnatwa set
538 Address_Clause_Overlay_Warnings := True;
539 Warn_On_Questionable_Layout := True;
540 Warn_On_Overridden_Size := True;
542 -- These warnings are removed from the -gnatwa set
544 Implementation_Unit_Warnings := False;
545 Warn_On_Non_Local_Exception := False;
546 No_Warn_On_Non_Local_Exception := True;
547 Warn_On_Reverse_Bit_Order := False;
548 Warn_On_Size_Alignment := False;
549 Warn_On_Unrepped_Components := False;
550 end Set_GNAT_Mode_Warnings;
552 ------------------------
553 -- Set_Warning_Switch --
554 ------------------------
556 function Set_Warning_Switch (C : Character) return Boolean is
563 All_Warnings (False);
564 No_Warn_On_Non_Local_Exception := True;
567 Warn_On_Bad_Fixed_Value := True;
570 Warn_On_Bad_Fixed_Value := False;
573 Constant_Condition_Warnings := True;
576 Constant_Condition_Warnings := False;
579 Warn_On_Dereference := True;
582 Warn_On_Dereference := False;
585 Warning_Mode := Treat_As_Error;
588 Warning_Mode := Treat_Run_Time_Warnings_As_Errors;
591 Check_Unreferenced_Formals := True;
594 Check_Unreferenced_Formals := False;
597 Warn_On_Unrecognized_Pragma := True;
600 Warn_On_Unrecognized_Pragma := False;
603 Warn_On_Hiding := True;
606 Warn_On_Hiding := False;
609 Implementation_Unit_Warnings := True;
612 Implementation_Unit_Warnings := False;
615 Warn_On_Obsolescent_Feature := True;
618 Warn_On_Obsolescent_Feature := False;
621 Warn_On_Constant := True;
624 Warn_On_Constant := False;
627 Elab_Warnings := True;
630 Elab_Warnings := False;
633 Warn_On_Modified_Unread := True;
636 Warn_On_Modified_Unread := False;
639 Warning_Mode := Normal;
642 Address_Clause_Overlay_Warnings := True;
645 Address_Clause_Overlay_Warnings := False;
648 Ineffective_Inline_Warnings := True;
651 Ineffective_Inline_Warnings := False;
654 Warn_On_Questionable_Missing_Parens := True;
657 Warn_On_Questionable_Missing_Parens := False;
660 Warn_On_Redundant_Constructs := True;
663 Warn_On_Redundant_Constructs := False;
666 Warning_Mode := Suppress;
669 Warn_On_Deleted_Code := True;
672 Warn_On_Deleted_Code := False;
675 Check_Unreferenced := True;
677 Check_Unreferenced_Formals := True;
680 Check_Unreferenced := False;
681 Check_Withs := False;
682 Check_Unreferenced_Formals := False;
685 Warn_On_No_Value_Assigned := True;
688 Warn_On_No_Value_Assigned := False;
691 Warn_On_Assumed_Low_Bound := True;
694 Warn_On_Assumed_Low_Bound := False;
697 Warn_On_Export_Import := True;
700 Warn_On_Export_Import := False;
703 Warn_On_Ada_2005_Compatibility := True;
704 Warn_On_Ada_2012_Compatibility := True;
707 Warn_On_Ada_2005_Compatibility := False;
708 Warn_On_Ada_2012_Compatibility := False;
711 Warn_On_Unchecked_Conversion := True;
714 Warn_On_Unchecked_Conversion := False;
717 if Ignore_Unrecognized_VWY_Switches then
718 Write_Line ("unrecognized switch -gnatw" & C & " ignored");
725 end Set_Warning_Switch;
731 procedure WA_Warnings is
733 Check_Unreferenced := True; -- -gnatwf/-gnatwu
734 Check_Unreferenced_Formals := True; -- -gnatwf/-gnatwu
735 Check_Withs := True; -- -gnatwu
736 Constant_Condition_Warnings := True; -- -gnatwc
737 Implementation_Unit_Warnings := True; -- -gnatwi
738 Ineffective_Inline_Warnings := True; -- -gnatwp
739 Warn_On_Ada_2005_Compatibility := True; -- -gnatwy
740 Warn_On_Ada_2012_Compatibility := True; -- -gnatwy
741 Warn_On_Anonymous_Allocators := True; -- -gnatw_a
742 Warn_On_Assertion_Failure := True; -- -gnatw.a
743 Warn_On_Assumed_Low_Bound := True; -- -gnatww
744 Warn_On_Bad_Fixed_Value := True; -- -gnatwb
745 Warn_On_Biased_Representation := True; -- -gnatw.b
746 Warn_On_Constant := True; -- -gnatwk
747 Warn_On_Export_Import := True; -- -gnatwx
748 Warn_On_Late_Primitives := True; -- -gnatw.j
749 Warn_On_Modified_Unread := True; -- -gnatwm
750 Warn_On_No_Value_Assigned := True; -- -gnatwv
751 Warn_On_Non_Local_Exception := True; -- -gnatw.x
752 Warn_On_Object_Renames_Function := True; -- -gnatw.r
753 Warn_On_Obsolescent_Feature := True; -- -gnatwj
754 Warn_On_Overlap := True; -- -gnatw.i
755 Warn_On_Parameter_Order := True; -- -gnatw.p
756 Warn_On_Questionable_Missing_Parens := True; -- -gnatwq
757 Warn_On_Redundant_Constructs := True; -- -gnatwr
758 Warn_On_Reverse_Bit_Order := True; -- -gnatw.v
759 Warn_On_Size_Alignment := True; -- -gnatw.z
760 Warn_On_Suspicious_Contract := True; -- -gnatw.t
761 Warn_On_Suspicious_Modulus_Value := True; -- -gnatw.m
762 Warn_On_Unchecked_Conversion := True; -- -gnatwz
763 Warn_On_Unrecognized_Pragma := True; -- -gnatwg
764 Warn_On_Unrepped_Components := True; -- -gnatw.c