1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1999-2018, 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_Assertion_Failure
:= Setting
;
60 Warn_On_Assumed_Low_Bound
:= Setting
;
61 Warn_On_Atomic_Synchronization
:= Setting
;
62 Warn_On_Bad_Fixed_Value
:= Setting
;
63 Warn_On_Biased_Representation
:= Setting
;
64 Warn_On_Constant
:= Setting
;
65 Warn_On_Deleted_Code
:= Setting
;
66 Warn_On_Dereference
:= Setting
;
67 Warn_On_Export_Import
:= Setting
;
68 Warn_On_Hiding
:= Setting
;
69 Warn_On_Late_Primitives
:= Setting
;
70 Warn_On_Modified_Unread
:= Setting
;
71 Warn_On_No_Value_Assigned
:= Setting
;
72 Warn_On_Non_Local_Exception
:= Setting
;
73 Warn_On_Object_Renames_Function
:= Setting
;
74 Warn_On_Obsolescent_Feature
:= Setting
;
75 Warn_On_Overlap
:= Setting
;
76 Warn_On_Overridden_Size
:= Setting
;
77 Warn_On_Parameter_Order
:= Setting
;
78 Warn_On_Questionable_Layout
:= Setting
;
79 Warn_On_Questionable_Missing_Parens
:= Setting
;
80 Warn_On_Record_Holes
:= Setting
;
81 Warn_On_Redundant_Constructs
:= Setting
;
82 Warn_On_Reverse_Bit_Order
:= Setting
;
83 Warn_On_Size_Alignment
:= Setting
;
84 Warn_On_Standard_Redefinition
:= Setting
;
85 Warn_On_Suspicious_Contract
:= Setting
;
86 Warn_On_Suspicious_Modulus_Value
:= Setting
;
87 Warn_On_Unchecked_Conversion
:= Setting
;
88 Warn_On_Unordered_Enumeration_Type
:= Setting
;
89 Warn_On_Unrecognized_Pragma
:= Setting
;
90 Warn_On_Unrepped_Components
:= Setting
;
91 Warn_On_Warnings_Off
:= Setting
;
94 ----------------------
95 -- Restore_Warnings --
96 ----------------------
98 procedure Restore_Warnings
(W
: Warning_Record
) is
100 Address_Clause_Overlay_Warnings
:=
101 W
.Address_Clause_Overlay_Warnings
;
102 Check_Unreferenced
:=
103 W
.Check_Unreferenced
;
104 Check_Unreferenced_Formals
:=
105 W
.Check_Unreferenced_Formals
;
108 Constant_Condition_Warnings
:=
109 W
.Constant_Condition_Warnings
;
112 Elab_Info_Messages
:=
113 W
.Elab_Info_Messages
;
114 Implementation_Unit_Warnings
:=
115 W
.Implementation_Unit_Warnings
;
116 Ineffective_Inline_Warnings
:=
117 W
.Ineffective_Inline_Warnings
;
118 List_Body_Required_Info
:=
119 W
.List_Body_Required_Info
;
120 List_Inherited_Aspects
:=
121 W
.List_Inherited_Aspects
;
122 No_Warn_On_Non_Local_Exception
:=
123 W
.No_Warn_On_Non_Local_Exception
;
124 Warning_Doc_Switch
:=
125 W
.Warning_Doc_Switch
;
126 Warn_On_Ada_2005_Compatibility
:=
127 W
.Warn_On_Ada_2005_Compatibility
;
128 Warn_On_Ada_2012_Compatibility
:=
129 W
.Warn_On_Ada_2012_Compatibility
;
130 Warn_On_All_Unread_Out_Parameters
:=
131 W
.Warn_On_All_Unread_Out_Parameters
;
132 Warn_On_Assertion_Failure
:=
133 W
.Warn_On_Assertion_Failure
;
134 Warn_On_Assumed_Low_Bound
:=
135 W
.Warn_On_Assumed_Low_Bound
;
136 Warn_On_Atomic_Synchronization
:=
137 W
.Warn_On_Atomic_Synchronization
;
138 Warn_On_Bad_Fixed_Value
:=
139 W
.Warn_On_Bad_Fixed_Value
;
140 Warn_On_Biased_Representation
:=
141 W
.Warn_On_Biased_Representation
;
144 Warn_On_Deleted_Code
:=
145 W
.Warn_On_Deleted_Code
;
146 Warn_On_Dereference
:=
147 W
.Warn_On_Dereference
;
148 Warn_On_Export_Import
:=
149 W
.Warn_On_Export_Import
;
152 Warn_On_Late_Primitives
:=
153 W
.Warn_On_Late_Primitives
;
154 Warn_On_Modified_Unread
:=
155 W
.Warn_On_Modified_Unread
;
156 Warn_On_No_Value_Assigned
:=
157 W
.Warn_On_No_Value_Assigned
;
158 Warn_On_Non_Local_Exception
:=
159 W
.Warn_On_Non_Local_Exception
;
160 Warn_On_Object_Renames_Function
:=
161 W
.Warn_On_Object_Renames_Function
;
162 Warn_On_Obsolescent_Feature
:=
163 W
.Warn_On_Obsolescent_Feature
;
166 Warn_On_Overridden_Size
:=
167 W
.Warn_On_Overridden_Size
;
168 Warn_On_Parameter_Order
:=
169 W
.Warn_On_Parameter_Order
;
170 Warn_On_Questionable_Layout
:=
171 W
.Warn_On_Questionable_Layout
;
172 Warn_On_Questionable_Missing_Parens
:=
173 W
.Warn_On_Questionable_Missing_Parens
;
174 Warn_On_Record_Holes
:=
175 W
.Warn_On_Record_Holes
;
176 Warn_On_Redundant_Constructs
:=
177 W
.Warn_On_Redundant_Constructs
;
178 Warn_On_Reverse_Bit_Order
:=
179 W
.Warn_On_Reverse_Bit_Order
;
180 Warn_On_Size_Alignment
:=
181 W
.Warn_On_Size_Alignment
;
182 Warn_On_Standard_Redefinition
:=
183 W
.Warn_On_Standard_Redefinition
;
184 Warn_On_Suspicious_Contract
:=
185 W
.Warn_On_Suspicious_Contract
;
186 Warn_On_Unchecked_Conversion
:=
187 W
.Warn_On_Unchecked_Conversion
;
188 Warn_On_Unordered_Enumeration_Type
:=
189 W
.Warn_On_Unordered_Enumeration_Type
;
190 Warn_On_Unrecognized_Pragma
:=
191 W
.Warn_On_Unrecognized_Pragma
;
192 Warn_On_Unrepped_Components
:=
193 W
.Warn_On_Unrepped_Components
;
194 Warn_On_Warnings_Off
:=
195 W
.Warn_On_Warnings_Off
;
196 end Restore_Warnings
;
202 function Save_Warnings
return Warning_Record
is
206 W
.Address_Clause_Overlay_Warnings
:=
207 Address_Clause_Overlay_Warnings
;
208 W
.Check_Unreferenced
:=
210 W
.Check_Unreferenced_Formals
:=
211 Check_Unreferenced_Formals
;
214 W
.Constant_Condition_Warnings
:=
215 Constant_Condition_Warnings
;
216 W
.Elab_Info_Messages
:=
220 W
.Implementation_Unit_Warnings
:=
221 Implementation_Unit_Warnings
;
222 W
.Ineffective_Inline_Warnings
:=
223 Ineffective_Inline_Warnings
;
224 W
.List_Body_Required_Info
:=
225 List_Body_Required_Info
;
226 W
.List_Inherited_Aspects
:=
227 List_Inherited_Aspects
;
228 W
.No_Warn_On_Non_Local_Exception
:=
229 No_Warn_On_Non_Local_Exception
;
230 W
.Warning_Doc_Switch
:=
232 W
.Warn_On_Ada_2005_Compatibility
:=
233 Warn_On_Ada_2005_Compatibility
;
234 W
.Warn_On_Ada_2012_Compatibility
:=
235 Warn_On_Ada_2012_Compatibility
;
236 W
.Warn_On_All_Unread_Out_Parameters
:=
237 Warn_On_All_Unread_Out_Parameters
;
238 W
.Warn_On_Assertion_Failure
:=
239 Warn_On_Assertion_Failure
;
240 W
.Warn_On_Assumed_Low_Bound
:=
241 Warn_On_Assumed_Low_Bound
;
242 W
.Warn_On_Atomic_Synchronization
:=
243 Warn_On_Atomic_Synchronization
;
244 W
.Warn_On_Bad_Fixed_Value
:=
245 Warn_On_Bad_Fixed_Value
;
246 W
.Warn_On_Biased_Representation
:=
247 Warn_On_Biased_Representation
;
248 W
.Warn_On_Constant
:=
250 W
.Warn_On_Deleted_Code
:=
251 Warn_On_Deleted_Code
;
252 W
.Warn_On_Dereference
:=
254 W
.Warn_On_Export_Import
:=
255 Warn_On_Export_Import
;
258 W
.Warn_On_Late_Primitives
:=
259 Warn_On_Late_Primitives
;
260 W
.Warn_On_Modified_Unread
:=
261 Warn_On_Modified_Unread
;
262 W
.Warn_On_No_Value_Assigned
:=
263 Warn_On_No_Value_Assigned
;
264 W
.Warn_On_Non_Local_Exception
:=
265 Warn_On_Non_Local_Exception
;
266 W
.Warn_On_Object_Renames_Function
:=
267 Warn_On_Object_Renames_Function
;
268 W
.Warn_On_Obsolescent_Feature
:=
269 Warn_On_Obsolescent_Feature
;
272 W
.Warn_On_Overridden_Size
:=
273 Warn_On_Overridden_Size
;
274 W
.Warn_On_Parameter_Order
:=
275 Warn_On_Parameter_Order
;
276 W
.Warn_On_Questionable_Layout
:=
277 Warn_On_Questionable_Layout
;
278 W
.Warn_On_Questionable_Missing_Parens
:=
279 Warn_On_Questionable_Missing_Parens
;
280 W
.Warn_On_Record_Holes
:=
281 Warn_On_Record_Holes
;
282 W
.Warn_On_Redundant_Constructs
:=
283 Warn_On_Redundant_Constructs
;
284 W
.Warn_On_Reverse_Bit_Order
:=
285 Warn_On_Reverse_Bit_Order
;
286 W
.Warn_On_Size_Alignment
:=
287 Warn_On_Size_Alignment
;
288 W
.Warn_On_Standard_Redefinition
:=
289 Warn_On_Standard_Redefinition
;
290 W
.Warn_On_Suspicious_Contract
:=
291 Warn_On_Suspicious_Contract
;
292 W
.Warn_On_Unchecked_Conversion
:=
293 Warn_On_Unchecked_Conversion
;
294 W
.Warn_On_Unordered_Enumeration_Type
:=
295 Warn_On_Unordered_Enumeration_Type
;
296 W
.Warn_On_Unrecognized_Pragma
:=
297 Warn_On_Unrecognized_Pragma
;
298 W
.Warn_On_Unrepped_Components
:=
299 Warn_On_Unrepped_Components
;
300 W
.Warn_On_Warnings_Off
:=
301 Warn_On_Warnings_Off
;
305 ----------------------------
306 -- Set_Dot_Warning_Switch --
307 ----------------------------
309 function Set_Dot_Warning_Switch
(C
: Character) return Boolean is
313 Warn_On_Assertion_Failure
:= True;
316 Warn_On_Assertion_Failure
:= False;
319 Warn_On_Biased_Representation
:= True;
322 Warn_On_Biased_Representation
:= False;
325 Warn_On_Unrepped_Components
:= True;
328 Warn_On_Unrepped_Components
:= False;
331 Warning_Doc_Switch
:= True;
334 Warning_Doc_Switch
:= False;
340 Warn_On_Elab_Access
:= True;
343 Warn_On_Elab_Access
:= False;
346 Set_GNAT_Mode_Warnings
;
349 Warn_On_Record_Holes
:= True;
352 Warn_On_Record_Holes
:= False;
355 Warn_On_Overlap
:= True;
358 Warn_On_Overlap
:= False;
361 Warn_On_Late_Primitives
:= True;
364 Warn_On_Late_Primitives
:= False;
367 Warn_On_Standard_Redefinition
:= True;
370 Warn_On_Standard_Redefinition
:= False;
373 List_Inherited_Aspects
:= True;
376 List_Inherited_Aspects
:= False;
379 Warn_On_Suspicious_Modulus_Value
:= True;
382 Warn_On_Suspicious_Modulus_Value
:= False;
385 Warn_On_Atomic_Synchronization
:= True;
388 Warn_On_Atomic_Synchronization
:= False;
391 Warn_On_All_Unread_Out_Parameters
:= True;
394 Warn_On_All_Unread_Out_Parameters
:= False;
397 Warn_On_Parameter_Order
:= True;
400 Warn_On_Parameter_Order
:= False;
403 Warn_On_Questionable_Layout
:= True;
406 Warn_On_Questionable_Layout
:= False;
409 Warn_On_Object_Renames_Function
:= True;
412 Warn_On_Object_Renames_Function
:= False;
415 Warn_On_Overridden_Size
:= True;
418 Warn_On_Overridden_Size
:= False;
421 Warn_On_Suspicious_Contract
:= True;
424 Warn_On_Suspicious_Contract
:= False;
427 Warn_On_Unordered_Enumeration_Type
:= True;
430 Warn_On_Unordered_Enumeration_Type
:= False;
433 Warn_On_Reverse_Bit_Order
:= True;
436 Warn_On_Reverse_Bit_Order
:= False;
439 Warn_On_Warnings_Off
:= True;
442 Warn_On_Warnings_Off
:= False;
445 Warn_On_Non_Local_Exception
:= True;
448 Warn_On_Non_Local_Exception
:= False;
449 No_Warn_On_Non_Local_Exception
:= True;
452 List_Body_Required_Info
:= True;
455 List_Body_Required_Info
:= False;
458 Warn_On_Size_Alignment
:= True;
461 Warn_On_Size_Alignment
:= False;
464 if Ignore_Unrecognized_VWY_Switches
then
465 Write_Line
("unrecognized switch -gnatw." & C
& " ignored");
472 end Set_Dot_Warning_Switch
;
474 -----------------------------------
475 -- Set_Underscore_Warning_Switch --
476 -----------------------------------
478 function Set_Underscore_Warning_Switch
(C
: Character) return Boolean is
482 if Ignore_Unrecognized_VWY_Switches
then
483 Write_Line
("unrecognized switch -gnatw_" & C
& " ignored");
490 end Set_Underscore_Warning_Switch
;
492 ----------------------------
493 -- Set_GNAT_Mode_Warnings --
494 ----------------------------
496 procedure Set_GNAT_Mode_Warnings
is
498 -- Set -gnatwa warnings and no others
500 All_Warnings
(False);
503 -- These warnings are added to the -gnatwa set
505 Address_Clause_Overlay_Warnings
:= True;
506 Warn_On_Questionable_Layout
:= True;
507 Warn_On_Overridden_Size
:= True;
509 -- These warnings are removed from the -gnatwa set
511 Implementation_Unit_Warnings
:= False;
512 Warn_On_Non_Local_Exception
:= False;
513 No_Warn_On_Non_Local_Exception
:= True;
514 Warn_On_Reverse_Bit_Order
:= False;
515 Warn_On_Size_Alignment
:= False;
516 Warn_On_Unrepped_Components
:= False;
517 end Set_GNAT_Mode_Warnings
;
519 ------------------------
520 -- Set_Warning_Switch --
521 ------------------------
523 function Set_Warning_Switch
(C
: Character) return Boolean is
530 All_Warnings
(False);
531 No_Warn_On_Non_Local_Exception
:= True;
534 Warn_On_Bad_Fixed_Value
:= True;
537 Warn_On_Bad_Fixed_Value
:= False;
540 Constant_Condition_Warnings
:= True;
543 Constant_Condition_Warnings
:= False;
546 Warn_On_Dereference
:= True;
549 Warn_On_Dereference
:= False;
552 Warning_Mode
:= Treat_As_Error
;
555 Warning_Mode
:= Treat_Run_Time_Warnings_As_Errors
;
558 Check_Unreferenced_Formals
:= True;
561 Check_Unreferenced_Formals
:= False;
564 Warn_On_Unrecognized_Pragma
:= True;
567 Warn_On_Unrecognized_Pragma
:= False;
570 Warn_On_Hiding
:= True;
573 Warn_On_Hiding
:= False;
576 Implementation_Unit_Warnings
:= True;
579 Implementation_Unit_Warnings
:= False;
582 Warn_On_Obsolescent_Feature
:= True;
585 Warn_On_Obsolescent_Feature
:= False;
588 Warn_On_Constant
:= True;
591 Warn_On_Constant
:= False;
594 Elab_Warnings
:= True;
597 Elab_Warnings
:= False;
600 Warn_On_Modified_Unread
:= True;
603 Warn_On_Modified_Unread
:= False;
606 Warning_Mode
:= Normal
;
609 Address_Clause_Overlay_Warnings
:= True;
612 Address_Clause_Overlay_Warnings
:= False;
615 Ineffective_Inline_Warnings
:= True;
618 Ineffective_Inline_Warnings
:= False;
621 Warn_On_Questionable_Missing_Parens
:= True;
624 Warn_On_Questionable_Missing_Parens
:= False;
627 Warn_On_Redundant_Constructs
:= True;
630 Warn_On_Redundant_Constructs
:= False;
633 Warning_Mode
:= Suppress
;
636 Warn_On_Deleted_Code
:= True;
639 Warn_On_Deleted_Code
:= False;
642 Check_Unreferenced
:= True;
644 Check_Unreferenced_Formals
:= True;
647 Check_Unreferenced
:= False;
648 Check_Withs
:= False;
649 Check_Unreferenced_Formals
:= False;
652 Warn_On_No_Value_Assigned
:= True;
655 Warn_On_No_Value_Assigned
:= False;
658 Warn_On_Assumed_Low_Bound
:= True;
661 Warn_On_Assumed_Low_Bound
:= False;
664 Warn_On_Export_Import
:= True;
667 Warn_On_Export_Import
:= False;
670 Warn_On_Ada_2005_Compatibility
:= True;
671 Warn_On_Ada_2012_Compatibility
:= True;
674 Warn_On_Ada_2005_Compatibility
:= False;
675 Warn_On_Ada_2012_Compatibility
:= False;
678 Warn_On_Unchecked_Conversion
:= True;
681 Warn_On_Unchecked_Conversion
:= False;
684 if Ignore_Unrecognized_VWY_Switches
then
685 Write_Line
("unrecognized switch -gnatw" & C
& " ignored");
692 end Set_Warning_Switch
;
698 procedure WA_Warnings
is
700 Check_Unreferenced
:= True; -- -gnatwf/-gnatwu
701 Check_Unreferenced_Formals
:= True; -- -gnatwf/-gnatwu
702 Check_Withs
:= True; -- -gnatwu
703 Constant_Condition_Warnings
:= True; -- -gnatwc
704 Implementation_Unit_Warnings
:= True; -- -gnatwi
705 Ineffective_Inline_Warnings
:= True; -- -gnatwp
706 Warn_On_Ada_2005_Compatibility
:= True; -- -gnatwy
707 Warn_On_Ada_2012_Compatibility
:= True; -- -gnatwy
708 Warn_On_Assertion_Failure
:= True; -- -gnatw.a
709 Warn_On_Assumed_Low_Bound
:= True; -- -gnatww
710 Warn_On_Bad_Fixed_Value
:= True; -- -gnatwb
711 Warn_On_Biased_Representation
:= True; -- -gnatw.b
712 Warn_On_Constant
:= True; -- -gnatwk
713 Warn_On_Export_Import
:= True; -- -gnatwx
714 Warn_On_Late_Primitives
:= True; -- -gnatw.j
715 Warn_On_Modified_Unread
:= True; -- -gnatwm
716 Warn_On_No_Value_Assigned
:= True; -- -gnatwv
717 Warn_On_Non_Local_Exception
:= True; -- -gnatw.x
718 Warn_On_Object_Renames_Function
:= True; -- -gnatw.r
719 Warn_On_Obsolescent_Feature
:= True; -- -gnatwj
720 Warn_On_Overlap
:= True; -- -gnatw.i
721 Warn_On_Parameter_Order
:= True; -- -gnatw.p
722 Warn_On_Questionable_Missing_Parens
:= True; -- -gnatwq
723 Warn_On_Redundant_Constructs
:= True; -- -gnatwr
724 Warn_On_Reverse_Bit_Order
:= True; -- -gnatw.v
725 Warn_On_Size_Alignment
:= True; -- -gnatw.z
726 Warn_On_Suspicious_Contract
:= True; -- -gnatw.t
727 Warn_On_Suspicious_Modulus_Value
:= True; -- -gnatw.m
728 Warn_On_Unchecked_Conversion
:= True; -- -gnatwz
729 Warn_On_Unrecognized_Pragma
:= True; -- -gnatwg
730 Warn_On_Unrepped_Components
:= True; -- -gnatw.c