1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1999-2014, 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_Modified_Unread
:= Setting
;
70 Warn_On_No_Value_Assigned
:= Setting
;
71 Warn_On_Non_Local_Exception
:= Setting
;
72 Warn_On_Object_Renames_Function
:= Setting
;
73 Warn_On_Obsolescent_Feature
:= Setting
;
74 Warn_On_Overlap
:= Setting
;
75 Warn_On_Overridden_Size
:= Setting
;
76 Warn_On_Parameter_Order
:= Setting
;
77 Warn_On_Questionable_Missing_Parens
:= Setting
;
78 Warn_On_Record_Holes
:= Setting
;
79 Warn_On_Redundant_Constructs
:= Setting
;
80 Warn_On_Reverse_Bit_Order
:= Setting
;
81 Warn_On_Size_Alignment
:= Setting
;
82 Warn_On_Standard_Redefinition
:= Setting
;
83 Warn_On_Suspicious_Contract
:= Setting
;
84 Warn_On_Suspicious_Modulus_Value
:= Setting
;
85 Warn_On_Unchecked_Conversion
:= Setting
;
86 Warn_On_Unordered_Enumeration_Type
:= Setting
;
87 Warn_On_Unrecognized_Pragma
:= Setting
;
88 Warn_On_Unrepped_Components
:= Setting
;
89 Warn_On_Warnings_Off
:= Setting
;
92 ----------------------
93 -- Restore_Warnings --
94 ----------------------
96 procedure Restore_Warnings
(W
: Warning_Record
) is
98 Address_Clause_Overlay_Warnings
:=
99 W
.Address_Clause_Overlay_Warnings
;
100 Check_Unreferenced
:=
101 W
.Check_Unreferenced
;
102 Check_Unreferenced_Formals
:=
103 W
.Check_Unreferenced_Formals
;
106 Constant_Condition_Warnings
:=
107 W
.Constant_Condition_Warnings
;
110 Elab_Info_Messages
:=
111 W
.Elab_Info_Messages
;
112 Implementation_Unit_Warnings
:=
113 W
.Implementation_Unit_Warnings
;
114 Ineffective_Inline_Warnings
:=
115 W
.Ineffective_Inline_Warnings
;
116 List_Body_Required_Info
:=
117 W
.List_Body_Required_Info
;
118 List_Inherited_Aspects
:=
119 W
.List_Inherited_Aspects
;
120 No_Warn_On_Non_Local_Exception
:=
121 W
.No_Warn_On_Non_Local_Exception
;
122 Warning_Doc_Switch
:=
123 W
.Warning_Doc_Switch
;
124 Warn_On_Ada_2005_Compatibility
:=
125 W
.Warn_On_Ada_2005_Compatibility
;
126 Warn_On_Ada_2012_Compatibility
:=
127 W
.Warn_On_Ada_2012_Compatibility
;
128 Warn_On_All_Unread_Out_Parameters
:=
129 W
.Warn_On_All_Unread_Out_Parameters
;
130 Warn_On_Assertion_Failure
:=
131 W
.Warn_On_Assertion_Failure
;
132 Warn_On_Assumed_Low_Bound
:=
133 W
.Warn_On_Assumed_Low_Bound
;
134 Warn_On_Atomic_Synchronization
:=
135 W
.Warn_On_Atomic_Synchronization
;
136 Warn_On_Bad_Fixed_Value
:=
137 W
.Warn_On_Bad_Fixed_Value
;
138 Warn_On_Biased_Representation
:=
139 W
.Warn_On_Biased_Representation
;
142 Warn_On_Deleted_Code
:=
143 W
.Warn_On_Deleted_Code
;
144 Warn_On_Dereference
:=
145 W
.Warn_On_Dereference
;
146 Warn_On_Export_Import
:=
147 W
.Warn_On_Export_Import
;
150 Warn_On_Modified_Unread
:=
151 W
.Warn_On_Modified_Unread
;
152 Warn_On_No_Value_Assigned
:=
153 W
.Warn_On_No_Value_Assigned
;
154 Warn_On_Non_Local_Exception
:=
155 W
.Warn_On_Non_Local_Exception
;
156 Warn_On_Object_Renames_Function
:=
157 W
.Warn_On_Object_Renames_Function
;
158 Warn_On_Obsolescent_Feature
:=
159 W
.Warn_On_Obsolescent_Feature
;
162 Warn_On_Overridden_Size
:=
163 W
.Warn_On_Overridden_Size
;
164 Warn_On_Parameter_Order
:=
165 W
.Warn_On_Parameter_Order
;
166 Warn_On_Questionable_Missing_Parens
:=
167 W
.Warn_On_Questionable_Missing_Parens
;
168 Warn_On_Record_Holes
:=
169 W
.Warn_On_Record_Holes
;
170 Warn_On_Redundant_Constructs
:=
171 W
.Warn_On_Redundant_Constructs
;
172 Warn_On_Reverse_Bit_Order
:=
173 W
.Warn_On_Reverse_Bit_Order
;
174 Warn_On_Size_Alignment
:=
175 W
.Warn_On_Size_Alignment
;
176 Warn_On_Standard_Redefinition
:=
177 W
.Warn_On_Standard_Redefinition
;
178 Warn_On_Suspicious_Contract
:=
179 W
.Warn_On_Suspicious_Contract
;
180 Warn_On_Unchecked_Conversion
:=
181 W
.Warn_On_Unchecked_Conversion
;
182 Warn_On_Unordered_Enumeration_Type
:=
183 W
.Warn_On_Unordered_Enumeration_Type
;
184 Warn_On_Unrecognized_Pragma
:=
185 W
.Warn_On_Unrecognized_Pragma
;
186 Warn_On_Unrepped_Components
:=
187 W
.Warn_On_Unrepped_Components
;
188 Warn_On_Warnings_Off
:=
189 W
.Warn_On_Warnings_Off
;
190 end Restore_Warnings
;
196 function Save_Warnings
return Warning_Record
is
200 W
.Address_Clause_Overlay_Warnings
:=
201 Address_Clause_Overlay_Warnings
;
202 W
.Check_Unreferenced
:=
204 W
.Check_Unreferenced_Formals
:=
205 Check_Unreferenced_Formals
;
208 W
.Constant_Condition_Warnings
:=
209 Constant_Condition_Warnings
;
210 W
.Elab_Info_Messages
:=
214 W
.Implementation_Unit_Warnings
:=
215 Implementation_Unit_Warnings
;
216 W
.Ineffective_Inline_Warnings
:=
217 Ineffective_Inline_Warnings
;
218 W
.List_Body_Required_Info
:=
219 List_Body_Required_Info
;
220 W
.List_Inherited_Aspects
:=
221 List_Inherited_Aspects
;
222 W
.No_Warn_On_Non_Local_Exception
:=
223 No_Warn_On_Non_Local_Exception
;
224 W
.Warning_Doc_Switch
:=
226 W
.Warn_On_Ada_2005_Compatibility
:=
227 Warn_On_Ada_2005_Compatibility
;
228 W
.Warn_On_Ada_2012_Compatibility
:=
229 Warn_On_Ada_2012_Compatibility
;
230 W
.Warn_On_All_Unread_Out_Parameters
:=
231 Warn_On_All_Unread_Out_Parameters
;
232 W
.Warn_On_Assertion_Failure
:=
233 Warn_On_Assertion_Failure
;
234 W
.Warn_On_Assumed_Low_Bound
:=
235 Warn_On_Assumed_Low_Bound
;
236 W
.Warn_On_Atomic_Synchronization
:=
237 Warn_On_Atomic_Synchronization
;
238 W
.Warn_On_Bad_Fixed_Value
:=
239 Warn_On_Bad_Fixed_Value
;
240 W
.Warn_On_Biased_Representation
:=
241 Warn_On_Biased_Representation
;
242 W
.Warn_On_Constant
:=
244 W
.Warn_On_Deleted_Code
:=
245 Warn_On_Deleted_Code
;
246 W
.Warn_On_Dereference
:=
248 W
.Warn_On_Export_Import
:=
249 Warn_On_Export_Import
;
252 W
.Warn_On_Modified_Unread
:=
253 Warn_On_Modified_Unread
;
254 W
.Warn_On_No_Value_Assigned
:=
255 Warn_On_No_Value_Assigned
;
256 W
.Warn_On_Non_Local_Exception
:=
257 Warn_On_Non_Local_Exception
;
258 W
.Warn_On_Object_Renames_Function
:=
259 Warn_On_Object_Renames_Function
;
260 W
.Warn_On_Obsolescent_Feature
:=
261 Warn_On_Obsolescent_Feature
;
264 W
.Warn_On_Overridden_Size
:=
265 Warn_On_Overridden_Size
;
266 W
.Warn_On_Parameter_Order
:=
267 Warn_On_Parameter_Order
;
268 W
.Warn_On_Questionable_Missing_Parens
:=
269 Warn_On_Questionable_Missing_Parens
;
270 W
.Warn_On_Record_Holes
:=
271 Warn_On_Record_Holes
;
272 W
.Warn_On_Redundant_Constructs
:=
273 Warn_On_Redundant_Constructs
;
274 W
.Warn_On_Reverse_Bit_Order
:=
275 Warn_On_Reverse_Bit_Order
;
276 W
.Warn_On_Size_Alignment
:=
277 Warn_On_Size_Alignment
;
278 W
.Warn_On_Standard_Redefinition
:=
279 Warn_On_Standard_Redefinition
;
280 W
.Warn_On_Suspicious_Contract
:=
281 Warn_On_Suspicious_Contract
;
282 W
.Warn_On_Unchecked_Conversion
:=
283 Warn_On_Unchecked_Conversion
;
284 W
.Warn_On_Unordered_Enumeration_Type
:=
285 Warn_On_Unordered_Enumeration_Type
;
286 W
.Warn_On_Unrecognized_Pragma
:=
287 Warn_On_Unrecognized_Pragma
;
288 W
.Warn_On_Unrepped_Components
:=
289 Warn_On_Unrepped_Components
;
290 W
.Warn_On_Warnings_Off
:=
291 Warn_On_Warnings_Off
;
295 ----------------------------
296 -- Set_Dot_Warning_Switch --
297 ----------------------------
299 function Set_Dot_Warning_Switch
(C
: Character) return Boolean is
303 Warn_On_Assertion_Failure
:= True;
306 Warn_On_Assertion_Failure
:= False;
309 Warn_On_Biased_Representation
:= True;
312 Warn_On_Biased_Representation
:= False;
315 Warn_On_Unrepped_Components
:= True;
318 Warn_On_Unrepped_Components
:= False;
321 Warning_Doc_Switch
:= True;
324 Warning_Doc_Switch
:= False;
330 Set_GNAT_Mode_Warnings
;
333 Warn_On_Record_Holes
:= True;
336 Warn_On_Record_Holes
:= False;
339 Warn_On_Overlap
:= True;
342 Warn_On_Overlap
:= False;
345 Warn_On_Standard_Redefinition
:= True;
348 Warn_On_Standard_Redefinition
:= False;
351 List_Inherited_Aspects
:= True;
354 List_Inherited_Aspects
:= False;
357 Warn_On_Suspicious_Modulus_Value
:= True;
360 Warn_On_Suspicious_Modulus_Value
:= False;
363 Warn_On_Atomic_Synchronization
:= True;
366 Warn_On_Atomic_Synchronization
:= False;
369 Warn_On_All_Unread_Out_Parameters
:= True;
372 Warn_On_All_Unread_Out_Parameters
:= False;
375 Warn_On_Parameter_Order
:= True;
378 Warn_On_Parameter_Order
:= False;
381 Warn_On_Object_Renames_Function
:= True;
384 Warn_On_Object_Renames_Function
:= False;
387 Warn_On_Overridden_Size
:= True;
390 Warn_On_Overridden_Size
:= False;
393 Warn_On_Suspicious_Contract
:= True;
396 Warn_On_Suspicious_Contract
:= False;
399 Warn_On_Unordered_Enumeration_Type
:= True;
402 Warn_On_Unordered_Enumeration_Type
:= False;
405 Warn_On_Reverse_Bit_Order
:= True;
408 Warn_On_Reverse_Bit_Order
:= False;
411 Warn_On_Warnings_Off
:= True;
414 Warn_On_Warnings_Off
:= False;
417 Warn_On_Non_Local_Exception
:= True;
420 Warn_On_Non_Local_Exception
:= False;
421 No_Warn_On_Non_Local_Exception
:= True;
424 List_Body_Required_Info
:= True;
427 List_Body_Required_Info
:= False;
430 Warn_On_Size_Alignment
:= True;
433 Warn_On_Size_Alignment
:= False;
436 if Ignore_Unrecognized_VWY_Switches
then
437 Write_Line
("unrecognized switch -gnatw." & C
& " ignored");
444 end Set_Dot_Warning_Switch
;
446 ----------------------------
447 -- Set_GNAT_Mode_Warnings --
448 ----------------------------
450 procedure Set_GNAT_Mode_Warnings
is
452 -- Set -gnatwa warnings and no others
454 All_Warnings
(False);
457 -- These warnings are added to the -gnatwa set
459 Address_Clause_Overlay_Warnings
:= True;
460 Warn_On_Overridden_Size
:= True;
462 -- These warnings are removed from the -gnatwa set
464 Implementation_Unit_Warnings
:= False;
465 Warn_On_Non_Local_Exception
:= False;
466 No_Warn_On_Non_Local_Exception
:= True;
467 Warn_On_Reverse_Bit_Order
:= False;
468 Warn_On_Size_Alignment
:= False;
469 Warn_On_Unrepped_Components
:= False;
470 end Set_GNAT_Mode_Warnings
;
472 ------------------------
473 -- Set_Warning_Switch --
474 ------------------------
476 function Set_Warning_Switch
(C
: Character) return Boolean is
483 All_Warnings
(False);
484 No_Warn_On_Non_Local_Exception
:= True;
487 Warn_On_Bad_Fixed_Value
:= True;
490 Warn_On_Bad_Fixed_Value
:= False;
493 Constant_Condition_Warnings
:= True;
496 Constant_Condition_Warnings
:= False;
499 Warn_On_Dereference
:= True;
502 Warn_On_Dereference
:= False;
505 Warning_Mode
:= Treat_As_Error
;
508 Check_Unreferenced_Formals
:= True;
511 Check_Unreferenced_Formals
:= False;
514 Warn_On_Unrecognized_Pragma
:= True;
517 Warn_On_Unrecognized_Pragma
:= False;
520 Warn_On_Hiding
:= True;
523 Warn_On_Hiding
:= False;
526 Implementation_Unit_Warnings
:= True;
529 Implementation_Unit_Warnings
:= False;
532 Warn_On_Obsolescent_Feature
:= True;
535 Warn_On_Obsolescent_Feature
:= False;
538 Warn_On_Constant
:= True;
541 Warn_On_Constant
:= False;
544 Elab_Warnings
:= True;
547 Elab_Warnings
:= False;
550 Warn_On_Modified_Unread
:= True;
553 Warn_On_Modified_Unread
:= False;
556 Warning_Mode
:= Normal
;
559 Address_Clause_Overlay_Warnings
:= True;
562 Address_Clause_Overlay_Warnings
:= False;
565 Ineffective_Inline_Warnings
:= True;
568 Ineffective_Inline_Warnings
:= False;
571 Warn_On_Questionable_Missing_Parens
:= True;
574 Warn_On_Questionable_Missing_Parens
:= False;
577 Warn_On_Redundant_Constructs
:= True;
580 Warn_On_Redundant_Constructs
:= False;
583 Warning_Mode
:= Suppress
;
586 Warn_On_Deleted_Code
:= True;
589 Warn_On_Deleted_Code
:= False;
592 Check_Unreferenced
:= True;
594 Check_Unreferenced_Formals
:= True;
597 Check_Unreferenced
:= False;
598 Check_Withs
:= False;
599 Check_Unreferenced_Formals
:= False;
602 Warn_On_No_Value_Assigned
:= True;
605 Warn_On_No_Value_Assigned
:= False;
608 Warn_On_Assumed_Low_Bound
:= True;
611 Warn_On_Assumed_Low_Bound
:= False;
614 Warn_On_Export_Import
:= True;
617 Warn_On_Export_Import
:= False;
620 Warn_On_Ada_2005_Compatibility
:= True;
621 Warn_On_Ada_2012_Compatibility
:= True;
624 Warn_On_Ada_2005_Compatibility
:= False;
625 Warn_On_Ada_2012_Compatibility
:= False;
628 Warn_On_Unchecked_Conversion
:= True;
631 Warn_On_Unchecked_Conversion
:= False;
634 if Ignore_Unrecognized_VWY_Switches
then
635 Write_Line
("unrecognized switch -gnatw" & C
& " ignored");
642 end Set_Warning_Switch
;
648 procedure WA_Warnings
is
650 Check_Unreferenced
:= True; -- -gnatwf/-gnatwu
651 Check_Unreferenced_Formals
:= True; -- -gnatwf/-gnatwu
652 Check_Withs
:= True; -- -gnatwu
653 Constant_Condition_Warnings
:= True; -- -gnatwc
654 Implementation_Unit_Warnings
:= True; -- -gnatwi
655 Ineffective_Inline_Warnings
:= True; -- -gnatwp
656 Warn_On_Ada_2005_Compatibility
:= True; -- -gnatwy
657 Warn_On_Ada_2012_Compatibility
:= True; -- -gnatwy
658 Warn_On_Assertion_Failure
:= True; -- -gnatw.a
659 Warn_On_Assumed_Low_Bound
:= True; -- -gnatww
660 Warn_On_Bad_Fixed_Value
:= True; -- -gnatwb
661 Warn_On_Biased_Representation
:= True; -- -gnatw.b
662 Warn_On_Constant
:= True; -- -gnatwk
663 Warn_On_Export_Import
:= True; -- -gnatwx
664 Warn_On_Modified_Unread
:= True; -- -gnatwm
665 Warn_On_No_Value_Assigned
:= True; -- -gnatwv
666 Warn_On_Non_Local_Exception
:= True; -- -gnatw.x
667 Warn_On_Object_Renames_Function
:= True; -- -gnatw.r
668 Warn_On_Obsolescent_Feature
:= True; -- -gnatwj
669 Warn_On_Overlap
:= True; -- -gnatw.i
670 Warn_On_Parameter_Order
:= True; -- -gnatw.p
671 Warn_On_Questionable_Missing_Parens
:= True; -- -gnatwq
672 Warn_On_Redundant_Constructs
:= True; -- -gnatwr
673 Warn_On_Reverse_Bit_Order
:= True; -- -gnatw.v
674 Warn_On_Size_Alignment
:= True; -- -gnatw.z
675 Warn_On_Suspicious_Contract
:= True; -- -gnatw.t
676 Warn_On_Suspicious_Modulus_Value
:= True; -- -gnatw.m
677 Warn_On_Unchecked_Conversion
:= True; -- -gnatwz
678 Warn_On_Unrecognized_Pragma
:= True; -- -gnatwg
679 Warn_On_Unrepped_Components
:= True; -- -gnatw.c