1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1999-2022, 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_Pedantic_Checks
:= Setting
;
80 Warn_On_Questionable_Layout
:= Setting
;
81 Warn_On_Questionable_Missing_Parens
:= Setting
;
82 Warn_On_Record_Holes
:= Setting
;
83 Warn_On_Component_Order
:= Setting
;
84 Warn_On_Redundant_Constructs
:= Setting
;
85 Warn_On_Reverse_Bit_Order
:= Setting
;
86 Warn_On_Size_Alignment
:= Setting
;
87 Warn_On_Standard_Redefinition
:= Setting
;
88 Warn_On_Suspicious_Contract
:= Setting
;
89 Warn_On_Suspicious_Modulus_Value
:= Setting
;
90 Warn_On_Unchecked_Conversion
:= Setting
;
91 Warn_On_Unknown_Compile_Time_Warning
:= Setting
;
92 Warn_On_Unordered_Enumeration_Type
:= Setting
;
93 Warn_On_Unrecognized_Pragma
:= Setting
;
94 Warn_On_Unrepped_Components
:= Setting
;
95 Warn_On_Warnings_Off
:= Setting
;
98 ----------------------
99 -- Restore_Warnings --
100 ----------------------
102 procedure Restore_Warnings
(W
: Warning_Record
) is
104 Address_Clause_Overlay_Warnings
:=
105 W
.Address_Clause_Overlay_Warnings
;
106 Check_Unreferenced
:=
107 W
.Check_Unreferenced
;
108 Check_Unreferenced_Formals
:=
109 W
.Check_Unreferenced_Formals
;
112 Constant_Condition_Warnings
:=
113 W
.Constant_Condition_Warnings
;
116 Elab_Info_Messages
:=
117 W
.Elab_Info_Messages
;
118 Implementation_Unit_Warnings
:=
119 W
.Implementation_Unit_Warnings
;
120 Ineffective_Inline_Warnings
:=
121 W
.Ineffective_Inline_Warnings
;
122 List_Body_Required_Info
:=
123 W
.List_Body_Required_Info
;
124 List_Inherited_Aspects
:=
125 W
.List_Inherited_Aspects
;
126 No_Warn_On_Non_Local_Exception
:=
127 W
.No_Warn_On_Non_Local_Exception
;
128 Warning_Doc_Switch
:=
129 W
.Warning_Doc_Switch
;
130 Warn_On_Ada_2005_Compatibility
:=
131 W
.Warn_On_Ada_2005_Compatibility
;
132 Warn_On_Ada_2012_Compatibility
:=
133 W
.Warn_On_Ada_2012_Compatibility
;
134 Warn_On_All_Unread_Out_Parameters
:=
135 W
.Warn_On_All_Unread_Out_Parameters
;
136 Warn_On_Anonymous_Allocators
:=
137 W
.Warn_On_Anonymous_Allocators
;
138 Warn_On_Assertion_Failure
:=
139 W
.Warn_On_Assertion_Failure
;
140 Warn_On_Assumed_Low_Bound
:=
141 W
.Warn_On_Assumed_Low_Bound
;
142 Warn_On_Atomic_Synchronization
:=
143 W
.Warn_On_Atomic_Synchronization
;
144 Warn_On_Bad_Fixed_Value
:=
145 W
.Warn_On_Bad_Fixed_Value
;
146 Warn_On_Biased_Representation
:=
147 W
.Warn_On_Biased_Representation
;
150 Warn_On_Deleted_Code
:=
151 W
.Warn_On_Deleted_Code
;
152 Warn_On_Dereference
:=
153 W
.Warn_On_Dereference
;
154 Warn_On_Export_Import
:=
155 W
.Warn_On_Export_Import
;
158 Warn_On_Late_Primitives
:=
159 W
.Warn_On_Late_Primitives
;
160 Warn_On_Modified_Unread
:=
161 W
.Warn_On_Modified_Unread
;
162 Warn_On_No_Value_Assigned
:=
163 W
.Warn_On_No_Value_Assigned
;
164 Warn_On_Non_Local_Exception
:=
165 W
.Warn_On_Non_Local_Exception
;
166 Warn_On_Object_Renames_Function
:=
167 W
.Warn_On_Object_Renames_Function
;
168 Warn_On_Obsolescent_Feature
:=
169 W
.Warn_On_Obsolescent_Feature
;
172 Warn_On_Overridden_Size
:=
173 W
.Warn_On_Overridden_Size
;
174 Warn_On_Parameter_Order
:=
175 W
.Warn_On_Parameter_Order
;
176 Warn_On_Pedantic_Checks
:=
177 W
.Warn_On_Pedantic_Checks
;
178 Warn_On_Questionable_Layout
:=
179 W
.Warn_On_Questionable_Layout
;
180 Warn_On_Questionable_Missing_Parens
:=
181 W
.Warn_On_Questionable_Missing_Parens
;
182 Warn_On_Record_Holes
:=
183 W
.Warn_On_Record_Holes
;
184 Warn_On_Component_Order
:=
185 W
.Warn_On_Component_Order
;
186 Warn_On_Redundant_Constructs
:=
187 W
.Warn_On_Redundant_Constructs
;
188 Warn_On_Reverse_Bit_Order
:=
189 W
.Warn_On_Reverse_Bit_Order
;
190 Warn_On_Size_Alignment
:=
191 W
.Warn_On_Size_Alignment
;
192 Warn_On_Standard_Redefinition
:=
193 W
.Warn_On_Standard_Redefinition
;
194 Warn_On_Suspicious_Contract
:=
195 W
.Warn_On_Suspicious_Contract
;
196 Warn_On_Unchecked_Conversion
:=
197 W
.Warn_On_Unchecked_Conversion
;
198 Warn_On_Unknown_Compile_Time_Warning
:=
199 W
.Warn_On_Unknown_Compile_Time_Warning
;
200 Warn_On_Unordered_Enumeration_Type
:=
201 W
.Warn_On_Unordered_Enumeration_Type
;
202 Warn_On_Unrecognized_Pragma
:=
203 W
.Warn_On_Unrecognized_Pragma
;
204 Warn_On_Unrepped_Components
:=
205 W
.Warn_On_Unrepped_Components
;
206 Warn_On_Warnings_Off
:=
207 W
.Warn_On_Warnings_Off
;
208 end Restore_Warnings
;
214 function Save_Warnings
return Warning_Record
is
218 W
.Address_Clause_Overlay_Warnings
:=
219 Address_Clause_Overlay_Warnings
;
220 W
.Check_Unreferenced
:=
222 W
.Check_Unreferenced_Formals
:=
223 Check_Unreferenced_Formals
;
226 W
.Constant_Condition_Warnings
:=
227 Constant_Condition_Warnings
;
228 W
.Elab_Info_Messages
:=
232 W
.Implementation_Unit_Warnings
:=
233 Implementation_Unit_Warnings
;
234 W
.Ineffective_Inline_Warnings
:=
235 Ineffective_Inline_Warnings
;
236 W
.List_Body_Required_Info
:=
237 List_Body_Required_Info
;
238 W
.List_Inherited_Aspects
:=
239 List_Inherited_Aspects
;
240 W
.No_Warn_On_Non_Local_Exception
:=
241 No_Warn_On_Non_Local_Exception
;
242 W
.Warning_Doc_Switch
:=
244 W
.Warn_On_Ada_2005_Compatibility
:=
245 Warn_On_Ada_2005_Compatibility
;
246 W
.Warn_On_Ada_2012_Compatibility
:=
247 Warn_On_Ada_2012_Compatibility
;
248 W
.Warn_On_All_Unread_Out_Parameters
:=
249 Warn_On_All_Unread_Out_Parameters
;
250 W
.Warn_On_Anonymous_Allocators
:=
251 Warn_On_Anonymous_Allocators
;
252 W
.Warn_On_Assertion_Failure
:=
253 Warn_On_Assertion_Failure
;
254 W
.Warn_On_Assumed_Low_Bound
:=
255 Warn_On_Assumed_Low_Bound
;
256 W
.Warn_On_Atomic_Synchronization
:=
257 Warn_On_Atomic_Synchronization
;
258 W
.Warn_On_Bad_Fixed_Value
:=
259 Warn_On_Bad_Fixed_Value
;
260 W
.Warn_On_Biased_Representation
:=
261 Warn_On_Biased_Representation
;
262 W
.Warn_On_Constant
:=
264 W
.Warn_On_Deleted_Code
:=
265 Warn_On_Deleted_Code
;
266 W
.Warn_On_Dereference
:=
268 W
.Warn_On_Export_Import
:=
269 Warn_On_Export_Import
;
272 W
.Warn_On_Late_Primitives
:=
273 Warn_On_Late_Primitives
;
274 W
.Warn_On_Modified_Unread
:=
275 Warn_On_Modified_Unread
;
276 W
.Warn_On_No_Value_Assigned
:=
277 Warn_On_No_Value_Assigned
;
278 W
.Warn_On_Non_Local_Exception
:=
279 Warn_On_Non_Local_Exception
;
280 W
.Warn_On_Object_Renames_Function
:=
281 Warn_On_Object_Renames_Function
;
282 W
.Warn_On_Obsolescent_Feature
:=
283 Warn_On_Obsolescent_Feature
;
286 W
.Warn_On_Overridden_Size
:=
287 Warn_On_Overridden_Size
;
288 W
.Warn_On_Parameter_Order
:=
289 Warn_On_Parameter_Order
;
290 W
.Warn_On_Pedantic_Checks
:=
291 Warn_On_Pedantic_Checks
;
292 W
.Warn_On_Questionable_Layout
:=
293 Warn_On_Questionable_Layout
;
294 W
.Warn_On_Questionable_Missing_Parens
:=
295 Warn_On_Questionable_Missing_Parens
;
296 W
.Warn_On_Record_Holes
:=
297 Warn_On_Record_Holes
;
298 W
.Warn_On_Component_Order
:=
299 Warn_On_Component_Order
;
300 W
.Warn_On_Redundant_Constructs
:=
301 Warn_On_Redundant_Constructs
;
302 W
.Warn_On_Reverse_Bit_Order
:=
303 Warn_On_Reverse_Bit_Order
;
304 W
.Warn_On_Size_Alignment
:=
305 Warn_On_Size_Alignment
;
306 W
.Warn_On_Standard_Redefinition
:=
307 Warn_On_Standard_Redefinition
;
308 W
.Warn_On_Suspicious_Contract
:=
309 Warn_On_Suspicious_Contract
;
310 W
.Warn_On_Unchecked_Conversion
:=
311 Warn_On_Unchecked_Conversion
;
312 W
.Warn_On_Unknown_Compile_Time_Warning
:=
313 Warn_On_Unknown_Compile_Time_Warning
;
314 W
.Warn_On_Unordered_Enumeration_Type
:=
315 Warn_On_Unordered_Enumeration_Type
;
316 W
.Warn_On_Unrecognized_Pragma
:=
317 Warn_On_Unrecognized_Pragma
;
318 W
.Warn_On_Unrepped_Components
:=
319 Warn_On_Unrepped_Components
;
320 W
.Warn_On_Warnings_Off
:=
321 Warn_On_Warnings_Off
;
325 ----------------------------
326 -- Set_Dot_Warning_Switch --
327 ----------------------------
329 function Set_Dot_Warning_Switch
(C
: Character) return Boolean is
333 Warn_On_Assertion_Failure
:= True;
336 Warn_On_Assertion_Failure
:= False;
339 Warn_On_Biased_Representation
:= True;
342 Warn_On_Biased_Representation
:= False;
345 Warn_On_Unrepped_Components
:= True;
348 Warn_On_Unrepped_Components
:= False;
351 Warning_Doc_Switch
:= True;
354 Warning_Doc_Switch
:= False;
360 Warn_On_Elab_Access
:= True;
363 Warn_On_Elab_Access
:= False;
366 Set_GNAT_Mode_Warnings
;
369 Warn_On_Record_Holes
:= True;
372 Warn_On_Record_Holes
:= False;
375 Warn_On_Overlap
:= True;
378 Warn_On_Overlap
:= False;
381 Warn_On_Late_Primitives
:= True;
384 Warn_On_Late_Primitives
:= False;
387 Warn_On_Standard_Redefinition
:= True;
390 Warn_On_Standard_Redefinition
:= False;
393 List_Inherited_Aspects
:= True;
396 List_Inherited_Aspects
:= False;
399 Warn_On_Suspicious_Modulus_Value
:= True;
402 Warn_On_Suspicious_Modulus_Value
:= False;
405 Warn_On_Atomic_Synchronization
:= True;
408 Warn_On_Atomic_Synchronization
:= False;
411 Warn_On_All_Unread_Out_Parameters
:= True;
414 Warn_On_All_Unread_Out_Parameters
:= False;
417 Warn_On_Parameter_Order
:= True;
420 Warn_On_Parameter_Order
:= False;
423 Warn_On_Questionable_Layout
:= True;
426 Warn_On_Questionable_Layout
:= False;
429 Warn_On_Object_Renames_Function
:= True;
432 Warn_On_Object_Renames_Function
:= False;
435 Warn_On_Overridden_Size
:= True;
438 Warn_On_Overridden_Size
:= False;
441 Warn_On_Suspicious_Contract
:= True;
444 Warn_On_Suspicious_Contract
:= False;
447 Warn_On_Unordered_Enumeration_Type
:= True;
450 Warn_On_Unordered_Enumeration_Type
:= False;
453 Warn_On_Reverse_Bit_Order
:= True;
456 Warn_On_Reverse_Bit_Order
:= False;
459 Warn_On_Warnings_Off
:= True;
462 Warn_On_Warnings_Off
:= False;
465 Warn_On_Non_Local_Exception
:= True;
468 Warn_On_Non_Local_Exception
:= False;
469 No_Warn_On_Non_Local_Exception
:= True;
472 List_Body_Required_Info
:= True;
475 List_Body_Required_Info
:= False;
478 Warn_On_Size_Alignment
:= True;
481 Warn_On_Size_Alignment
:= False;
484 if Ignore_Unrecognized_VWY_Switches
then
485 Write_Line
("unrecognized switch -gnatw." & C
& " ignored");
492 end Set_Dot_Warning_Switch
;
494 -----------------------------------
495 -- Set_Underscore_Warning_Switch --
496 -----------------------------------
498 function Set_Underscore_Warning_Switch
(C
: Character) return Boolean is
502 Warn_On_Anonymous_Allocators
:= True;
505 Warn_On_Anonymous_Allocators
:= False;
508 Warn_On_Unknown_Compile_Time_Warning
:= True;
511 Warn_On_Unknown_Compile_Time_Warning
:= False;
514 Warn_On_Pedantic_Checks
:= True;
517 Warn_On_Pedantic_Checks
:= False;
520 Warn_On_Component_Order
:= True;
523 Warn_On_Component_Order
:= False;
526 if Ignore_Unrecognized_VWY_Switches
then
527 Write_Line
("unrecognized switch -gnatw_" & C
& " ignored");
534 end Set_Underscore_Warning_Switch
;
536 ----------------------------
537 -- Set_GNAT_Mode_Warnings --
538 ----------------------------
540 procedure Set_GNAT_Mode_Warnings
is
542 -- Set -gnatwa warnings and no others
544 All_Warnings
(False);
547 -- These warnings are added to the -gnatwa set
549 Address_Clause_Overlay_Warnings
:= True;
550 Warn_On_Questionable_Layout
:= True;
551 Warn_On_Overridden_Size
:= True;
553 -- These warnings are removed from the -gnatwa set
555 Implementation_Unit_Warnings
:= False;
556 Warn_On_Non_Local_Exception
:= False;
557 No_Warn_On_Non_Local_Exception
:= True;
558 Warn_On_Reverse_Bit_Order
:= False;
559 Warn_On_Size_Alignment
:= False;
560 Warn_On_Unrepped_Components
:= False;
561 end Set_GNAT_Mode_Warnings
;
563 ------------------------
564 -- Set_Warning_Switch --
565 ------------------------
567 function Set_Warning_Switch
(C
: Character) return Boolean is
574 All_Warnings
(False);
575 No_Warn_On_Non_Local_Exception
:= True;
578 Warn_On_Bad_Fixed_Value
:= True;
581 Warn_On_Bad_Fixed_Value
:= False;
584 Constant_Condition_Warnings
:= True;
587 Constant_Condition_Warnings
:= False;
590 Warn_On_Dereference
:= True;
593 Warn_On_Dereference
:= False;
596 Warning_Mode
:= Treat_As_Error
;
599 Warning_Mode
:= Treat_Run_Time_Warnings_As_Errors
;
602 Check_Unreferenced_Formals
:= True;
605 Check_Unreferenced_Formals
:= False;
608 Warn_On_Unrecognized_Pragma
:= True;
611 Warn_On_Unrecognized_Pragma
:= False;
614 Warn_On_Hiding
:= True;
617 Warn_On_Hiding
:= False;
620 Implementation_Unit_Warnings
:= True;
623 Implementation_Unit_Warnings
:= False;
626 Warn_On_Obsolescent_Feature
:= True;
629 Warn_On_Obsolescent_Feature
:= False;
632 Warn_On_Constant
:= True;
635 Warn_On_Constant
:= False;
638 Elab_Warnings
:= True;
641 Elab_Warnings
:= False;
644 Warn_On_Modified_Unread
:= True;
647 Warn_On_Modified_Unread
:= False;
650 Warning_Mode
:= Normal
;
653 Address_Clause_Overlay_Warnings
:= True;
656 Address_Clause_Overlay_Warnings
:= False;
659 Ineffective_Inline_Warnings
:= True;
662 Ineffective_Inline_Warnings
:= False;
665 Warn_On_Questionable_Missing_Parens
:= True;
668 Warn_On_Questionable_Missing_Parens
:= False;
671 Warn_On_Redundant_Constructs
:= True;
674 Warn_On_Redundant_Constructs
:= False;
677 Warning_Mode
:= Suppress
;
680 Warn_On_Deleted_Code
:= True;
683 Warn_On_Deleted_Code
:= False;
686 Check_Unreferenced
:= True;
688 Check_Unreferenced_Formals
:= True;
691 Check_Unreferenced
:= False;
692 Check_Withs
:= False;
693 Check_Unreferenced_Formals
:= False;
696 Warn_On_No_Value_Assigned
:= True;
699 Warn_On_No_Value_Assigned
:= False;
702 Warn_On_Assumed_Low_Bound
:= True;
705 Warn_On_Assumed_Low_Bound
:= False;
708 Warn_On_Export_Import
:= True;
711 Warn_On_Export_Import
:= False;
714 Warn_On_Ada_2005_Compatibility
:= True;
715 Warn_On_Ada_2012_Compatibility
:= True;
718 Warn_On_Ada_2005_Compatibility
:= False;
719 Warn_On_Ada_2012_Compatibility
:= False;
722 Warn_On_Unchecked_Conversion
:= True;
725 Warn_On_Unchecked_Conversion
:= False;
728 if Ignore_Unrecognized_VWY_Switches
then
729 Write_Line
("unrecognized switch -gnatw" & C
& " ignored");
736 end Set_Warning_Switch
;
742 procedure WA_Warnings
is
744 Check_Unreferenced
:= True; -- -gnatwf/-gnatwu
745 Check_Unreferenced_Formals
:= True; -- -gnatwf/-gnatwu
746 Check_Withs
:= True; -- -gnatwu
747 Constant_Condition_Warnings
:= True; -- -gnatwc
748 Implementation_Unit_Warnings
:= True; -- -gnatwi
749 Ineffective_Inline_Warnings
:= True; -- -gnatwp
750 Warn_On_Ada_2005_Compatibility
:= True; -- -gnatwy
751 Warn_On_Ada_2012_Compatibility
:= True; -- -gnatwy
752 Warn_On_Anonymous_Allocators
:= True; -- -gnatw_a
753 Warn_On_Assertion_Failure
:= True; -- -gnatw.a
754 Warn_On_Assumed_Low_Bound
:= True; -- -gnatww
755 Warn_On_Bad_Fixed_Value
:= True; -- -gnatwb
756 Warn_On_Biased_Representation
:= True; -- -gnatw.b
757 Warn_On_Constant
:= True; -- -gnatwk
758 Warn_On_Export_Import
:= True; -- -gnatwx
759 Warn_On_Late_Primitives
:= True; -- -gnatw.j
760 Warn_On_Modified_Unread
:= True; -- -gnatwm
761 Warn_On_No_Value_Assigned
:= True; -- -gnatwv
762 Warn_On_Non_Local_Exception
:= True; -- -gnatw.x
763 Warn_On_Object_Renames_Function
:= True; -- -gnatw.r
764 Warn_On_Obsolescent_Feature
:= True; -- -gnatwj
765 Warn_On_Overlap
:= True; -- -gnatw.i
766 Warn_On_Parameter_Order
:= True; -- -gnatw.p
767 Warn_On_Questionable_Missing_Parens
:= True; -- -gnatwq
768 Warn_On_Redundant_Constructs
:= True; -- -gnatwr
769 Warn_On_Reverse_Bit_Order
:= True; -- -gnatw.v
770 Warn_On_Size_Alignment
:= True; -- -gnatw.z
771 Warn_On_Suspicious_Contract
:= True; -- -gnatw.t
772 Warn_On_Suspicious_Modulus_Value
:= True; -- -gnatw.m
773 Warn_On_Unchecked_Conversion
:= True; -- -gnatwz
774 Warn_On_Unrecognized_Pragma
:= True; -- -gnatwg
775 Warn_On_Unrepped_Components
:= True; -- -gnatw.c