1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT COMPILER COMPONENTS                         --
4--                                                                          --
5--                               W A R N S W                                --
6--                                                                          --
7--                                 S p e c                                  --
8--                                                                          --
9--          Copyright (C) 1999-2020, Free Software Foundation, Inc.         --
10--                                                                          --
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.          --
20--                                                                          --
21-- GNAT was originally developed  by the GNAT team at  New York University. --
22-- Extensive contributions were provided by Ada Core Technologies Inc.      --
23--                                                                          --
24------------------------------------------------------------------------------
25
26--  This unit contains the routines used to handle setting of warning options
27
28package Warnsw is
29
30   -------------------
31   -- Warning Flags --
32   -------------------
33
34   --  These flags are activated or deactivated by -gnatw switches and control
35   --  whether warnings of a given class will be generated or not.
36
37   --  Note: most of these flags are still in opt, but the plan is to move them
38   --  here as time goes by. And in fact a really nice idea would be to put
39   --  them all in a Warn_Record so that they would be easy to save/restore.
40
41   Warn_On_Anonymous_Allocators : Boolean := False;
42   --  Warn when allocators for anonymous access types are present, which,
43   --  although not illegal in Ada, may be confusing to users due to how
44   --  accessibility checks get generated. Off by default, modified by use
45   --  of -gnatw_a/_A and set as part of -gnatwa.
46
47   Warn_On_Late_Primitives : Boolean := False;
48   --  Warn when tagged type public primitives are defined after its private
49   --  extensions.
50
51   Warn_On_Unknown_Compile_Time_Warning : Boolean := True;
52   --  Warn on a pragma Compile_Time_Warning whose condition has a value that
53   --  is not known at compile time.
54
55   Warn_On_Overridden_Size : Boolean := False;
56   --  Warn when explicit record component clause or array component_size
57   --  clause specifies a size that overrides a size for the type which was
58   --  set with an explicit size clause. Off by default, modified by use of
59   --  -gnatw.s/.S (but not -gnatwa).
60
61   Warn_On_Questionable_Layout : Boolean := False;
62   --  Warn when default layout of a record type is questionable for run-time
63   --  efficiency reasons and would be improved by reordering the components.
64   --  Off by default, modified by use of -gnatw.q/.Q (but not -gnatwa).
65
66   --  WARNING: There is a matching C declaration of this variable in fe.h
67
68   Warn_On_Record_Holes : Boolean := False;
69   --  Warn when explicit record component clauses leave uncovered holes (gaps)
70   --  in a record layout. Off by default, set by -gnatw.h (but not -gnatwa).
71
72   Warn_On_Component_Order : Boolean := False;
73   --  Warn when record component clauses are out of order with respect to the
74   --  component declarations, or if the memory layout is out of order with
75   --  respect to component declarations and clauses.  Off by default, set by
76   --  -gnatw_r (but not -gnatwa).
77
78   Warn_On_Size_Alignment : Boolean := True;
79   --  Warn when explicit Size and Alignment clauses are given for a type, and
80   --  the size is not a multiple of the alignment. Off by default, modified
81   --  by use of -gnatw.z/.Z and set as part of -gnatwa.
82
83   Warn_On_Standard_Redefinition : Boolean := False;
84   --  Warn when a program defines an identifier that matches a name in
85   --  Standard. Off by default, modified by use of -gnatw.k/.K (but not
86   --  by -gnatwa).
87
88   -----------------------------------
89   -- Saving and Restoring Warnings --
90   -----------------------------------
91
92   --  Type used to save and restore warnings
93
94   type Warning_Record is record
95      Address_Clause_Overlay_Warnings      : Boolean;
96      Check_Unreferenced                   : Boolean;
97      Check_Unreferenced_Formals           : Boolean;
98      Check_Withs                          : Boolean;
99      Constant_Condition_Warnings          : Boolean;
100      Elab_Info_Messages                   : Boolean;
101      Elab_Warnings                        : Boolean;
102      Implementation_Unit_Warnings         : Boolean;
103      Ineffective_Inline_Warnings          : Boolean;
104      List_Body_Required_Info              : Boolean;
105      List_Inherited_Aspects               : Boolean;
106      No_Warn_On_Non_Local_Exception       : Boolean;
107      Warning_Doc_Switch                   : Boolean;
108      Warn_On_Ada_2005_Compatibility       : Boolean;
109      Warn_On_Ada_2012_Compatibility       : Boolean;
110      Warn_On_All_Unread_Out_Parameters    : Boolean;
111      Warn_On_Anonymous_Allocators         : Boolean;
112      Warn_On_Assertion_Failure            : Boolean;
113      Warn_On_Assumed_Low_Bound            : Boolean;
114      Warn_On_Atomic_Synchronization       : Boolean;
115      Warn_On_Bad_Fixed_Value              : Boolean;
116      Warn_On_Biased_Representation        : Boolean;
117      Warn_On_Constant                     : Boolean;
118      Warn_On_Deleted_Code                 : Boolean;
119      Warn_On_Dereference                  : Boolean;
120      Warn_On_Export_Import                : Boolean;
121      Warn_On_Hiding                       : Boolean;
122      Warn_On_Late_Primitives              : Boolean;
123      Warn_On_Modified_Unread              : Boolean;
124      Warn_On_No_Value_Assigned            : Boolean;
125      Warn_On_Non_Local_Exception          : Boolean;
126      Warn_On_Object_Renames_Function      : Boolean;
127      Warn_On_Obsolescent_Feature          : Boolean;
128      Warn_On_Overlap                      : Boolean;
129      Warn_On_Overridden_Size              : Boolean;
130      Warn_On_Parameter_Order              : Boolean;
131      Warn_On_Questionable_Layout          : Boolean;
132      Warn_On_Questionable_Missing_Parens  : Boolean;
133      Warn_On_Record_Holes                 : Boolean;
134      Warn_On_Component_Order              : Boolean;
135      Warn_On_Redundant_Constructs         : Boolean;
136      Warn_On_Reverse_Bit_Order            : Boolean;
137      Warn_On_Size_Alignment               : Boolean;
138      Warn_On_Standard_Redefinition        : Boolean;
139      Warn_On_Suspicious_Contract          : Boolean;
140      Warn_On_Suspicious_Modulus_Value     : Boolean;
141      Warn_On_Unchecked_Conversion         : Boolean;
142      Warn_On_Unknown_Compile_Time_Warning : Boolean;
143      Warn_On_Unordered_Enumeration_Type   : Boolean;
144      Warn_On_Unrecognized_Pragma          : Boolean;
145      Warn_On_Unrepped_Components          : Boolean;
146      Warn_On_Warnings_Off                 : Boolean;
147   end record;
148
149   function Save_Warnings return Warning_Record;
150   --  Returns current settingh of warnings
151
152   procedure Restore_Warnings (W : Warning_Record);
153   --  Restores current settings of warning flags from W
154
155   -----------------
156   -- Subprograms --
157   -----------------
158
159   function Set_Warning_Switch (C : Character) return Boolean;
160   --  This function sets the warning switch or switches corresponding to the
161   --  given character. It is used to process a -gnatw switch on the command
162   --  line, or a character in a string literal in pragma Warnings. Returns
163   --  True for valid warning character C, False for invalid character.
164
165   function Set_Dot_Warning_Switch (C : Character) return Boolean;
166   --  This function sets the warning switch or switches corresponding to the
167   --  given character preceded by a dot. Used to process a -gnatw. switch on
168   --  the command line or .C in a string literal in pragma Warnings. Returns
169   --  True for valid warning character C, False for invalid character.
170
171   function Set_Underscore_Warning_Switch (C : Character) return Boolean;
172   --  This function sets the warning switch or switches corresponding to the
173   --  given character preceded by an underscore. Used to process a -gnatw_
174   --  switch on the command line or _C in a string literal in pragma Warnings.
175   --  Returns True for valid warnings character C, False for invalid
176   --  character.
177
178   procedure Set_GNAT_Mode_Warnings;
179   --  This is called in -gnatg mode to set the warnings for gnat mode. It is
180   --  also used to set the proper warning statuses for -gnatw.g. Note that
181   --  this set of warnings is neither a subset nor a superset of -gnatwa, it
182   --  enables warnings that are not included in -gnatwa and disables warnings
183   --  that are included in -gnatwa (such as Warn_On_Implementation_Units, that
184   --  we clearly want to be False for units built with -gnatg).
185
186end Warnsw;
187