1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1999-2017, 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_GNAT_Mode_Warnings --
476 ----------------------------
478 procedure Set_GNAT_Mode_Warnings
is
480 -- Set -gnatwa warnings and no others
482 All_Warnings
(False);
485 -- These warnings are added to the -gnatwa set
487 Address_Clause_Overlay_Warnings
:= True;
488 Warn_On_Overridden_Size
:= True;
490 -- These warnings are removed from the -gnatwa set
492 Implementation_Unit_Warnings
:= False;
493 Warn_On_Non_Local_Exception
:= False;
494 No_Warn_On_Non_Local_Exception
:= True;
495 Warn_On_Reverse_Bit_Order
:= False;
496 Warn_On_Size_Alignment
:= False;
497 Warn_On_Unrepped_Components
:= False;
498 end Set_GNAT_Mode_Warnings
;
500 ------------------------
501 -- Set_Warning_Switch --
502 ------------------------
504 function Set_Warning_Switch
(C
: Character) return Boolean is
511 All_Warnings
(False);
512 No_Warn_On_Non_Local_Exception
:= True;
515 Warn_On_Bad_Fixed_Value
:= True;
518 Warn_On_Bad_Fixed_Value
:= False;
521 Constant_Condition_Warnings
:= True;
524 Constant_Condition_Warnings
:= False;
527 Warn_On_Dereference
:= True;
530 Warn_On_Dereference
:= False;
533 Warning_Mode
:= Treat_As_Error
;
536 Warning_Mode
:= Treat_Run_Time_Warnings_As_Errors
;
539 Check_Unreferenced_Formals
:= True;
542 Check_Unreferenced_Formals
:= False;
545 Warn_On_Unrecognized_Pragma
:= True;
548 Warn_On_Unrecognized_Pragma
:= False;
551 Warn_On_Hiding
:= True;
554 Warn_On_Hiding
:= False;
557 Implementation_Unit_Warnings
:= True;
560 Implementation_Unit_Warnings
:= False;
563 Warn_On_Obsolescent_Feature
:= True;
566 Warn_On_Obsolescent_Feature
:= False;
569 Warn_On_Constant
:= True;
572 Warn_On_Constant
:= False;
575 Elab_Warnings
:= True;
578 Elab_Warnings
:= False;
581 Warn_On_Modified_Unread
:= True;
584 Warn_On_Modified_Unread
:= False;
587 Warning_Mode
:= Normal
;
590 Address_Clause_Overlay_Warnings
:= True;
593 Address_Clause_Overlay_Warnings
:= False;
596 Ineffective_Inline_Warnings
:= True;
599 Ineffective_Inline_Warnings
:= False;
602 Warn_On_Questionable_Missing_Parens
:= True;
605 Warn_On_Questionable_Missing_Parens
:= False;
608 Warn_On_Redundant_Constructs
:= True;
611 Warn_On_Redundant_Constructs
:= False;
614 Warning_Mode
:= Suppress
;
617 Warn_On_Deleted_Code
:= True;
620 Warn_On_Deleted_Code
:= False;
623 Check_Unreferenced
:= True;
625 Check_Unreferenced_Formals
:= True;
628 Check_Unreferenced
:= False;
629 Check_Withs
:= False;
630 Check_Unreferenced_Formals
:= False;
633 Warn_On_No_Value_Assigned
:= True;
636 Warn_On_No_Value_Assigned
:= False;
639 Warn_On_Assumed_Low_Bound
:= True;
642 Warn_On_Assumed_Low_Bound
:= False;
645 Warn_On_Export_Import
:= True;
648 Warn_On_Export_Import
:= False;
651 Warn_On_Ada_2005_Compatibility
:= True;
652 Warn_On_Ada_2012_Compatibility
:= True;
655 Warn_On_Ada_2005_Compatibility
:= False;
656 Warn_On_Ada_2012_Compatibility
:= False;
659 Warn_On_Unchecked_Conversion
:= True;
662 Warn_On_Unchecked_Conversion
:= False;
665 if Ignore_Unrecognized_VWY_Switches
then
666 Write_Line
("unrecognized switch -gnatw" & C
& " ignored");
673 end Set_Warning_Switch
;
679 procedure WA_Warnings
is
681 Check_Unreferenced
:= True; -- -gnatwf/-gnatwu
682 Check_Unreferenced_Formals
:= True; -- -gnatwf/-gnatwu
683 Check_Withs
:= True; -- -gnatwu
684 Constant_Condition_Warnings
:= True; -- -gnatwc
685 Implementation_Unit_Warnings
:= True; -- -gnatwi
686 Ineffective_Inline_Warnings
:= True; -- -gnatwp
687 Warn_On_Ada_2005_Compatibility
:= True; -- -gnatwy
688 Warn_On_Ada_2012_Compatibility
:= True; -- -gnatwy
689 Warn_On_Assertion_Failure
:= True; -- -gnatw.a
690 Warn_On_Assumed_Low_Bound
:= True; -- -gnatww
691 Warn_On_Bad_Fixed_Value
:= True; -- -gnatwb
692 Warn_On_Biased_Representation
:= True; -- -gnatw.b
693 Warn_On_Constant
:= True; -- -gnatwk
694 Warn_On_Export_Import
:= True; -- -gnatwx
695 Warn_On_Late_Primitives
:= True; -- -gnatw.j
696 Warn_On_Modified_Unread
:= True; -- -gnatwm
697 Warn_On_No_Value_Assigned
:= True; -- -gnatwv
698 Warn_On_Non_Local_Exception
:= True; -- -gnatw.x
699 Warn_On_Object_Renames_Function
:= True; -- -gnatw.r
700 Warn_On_Obsolescent_Feature
:= True; -- -gnatwj
701 Warn_On_Overlap
:= True; -- -gnatw.i
702 Warn_On_Parameter_Order
:= True; -- -gnatw.p
703 Warn_On_Questionable_Missing_Parens
:= True; -- -gnatwq
704 Warn_On_Redundant_Constructs
:= True; -- -gnatwr
705 Warn_On_Reverse_Bit_Order
:= True; -- -gnatw.v
706 Warn_On_Size_Alignment
:= True; -- -gnatw.z
707 Warn_On_Suspicious_Contract
:= True; -- -gnatw.t
708 Warn_On_Suspicious_Modulus_Value
:= True; -- -gnatw.m
709 Warn_On_Unchecked_Conversion
:= True; -- -gnatwz
710 Warn_On_Unrecognized_Pragma
:= True; -- -gnatwg
711 Warn_On_Unrepped_Components
:= True; -- -gnatw.c