1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1999-2002 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
28 with Atree; use Atree;
29 with Einfo; use Einfo;
30 with Errout; use Errout;
31 with Fname; use Fname;
33 with Nlists; use Nlists;
36 with Sem_Util; use Sem_Util;
37 with Sinfo; use Sinfo;
38 with Sinput; use Sinput;
39 with Snames; use Snames;
40 with Stand; use Stand;
43 package body Sem_Warn is
45 -- The following table collects Id's of entities that are potentially
46 -- unreferenced. See Check_Unset_Reference for further details.
48 package Unreferenced_Entities is new Table.Table (
49 Table_Component_Type => Entity_Id,
50 Table_Index_Type => Nat,
52 Table_Initial => Alloc.Unreferenced_Entities_Initial,
53 Table_Increment => Alloc.Unreferenced_Entities_Increment,
54 Table_Name => "Unreferenced_Entities");
56 -- One entry is made in the following table for each branch of
57 -- a conditional, e.g. an if-then-elsif-else-endif structure
58 -- creates three entries in this table.
60 type Branch_Entry is record
62 -- Location for warnings associated with this branch
65 -- List of entities defined for the first time in this branch. On
66 -- exit from a conditional structure, any entity that is in the
67 -- list of all branches is removed (and the entity flagged as
68 -- defined by the conditional as a whole). Thus after processing
69 -- a conditional, Defs contains a list of entities defined in this
70 -- branch for the first time, but not defined at all in some other
71 -- branch of the same conditional. A value of No_Elist is used to
72 -- represent the initial empty list.
75 -- Index of next branch for this conditional, zero = last branch
78 package Branch_Table is new Table.Table (
79 Table_Component_Type => Branch_Entry,
80 Table_Index_Type => Nat,
82 Table_Initial => Alloc.Branches_Initial,
83 Table_Increment => Alloc.Branches_Increment,
84 Table_Name => "Branches");
86 -- The following table is used to represent conditionals, there is
87 -- one entry in this table for each conditional structure.
89 type Conditional_Entry is record
91 -- True for IF statement, False for CASE statement
94 -- Index in Branch table of first branch, zero = none yet
97 -- Index in Branch table of current branch, zero = none yet
100 package Conditional_Table is new Table.Table (
101 Table_Component_Type => Conditional_Entry,
102 Table_Index_Type => Nat,
103 Table_Low_Bound => 1,
104 Table_Initial => Alloc.Conditionals_Initial,
105 Table_Increment => Alloc.Conditionals_Increment,
106 Table_Name => "Conditionals");
108 -- The following table is a stack that keeps track of the current
109 -- conditional. The Last entry is the top of the stack. An Empty
110 -- entry represents the start of a compilation unit. Non-zero
111 -- entries in the stack are indexes into the conditional table.
113 package Conditional_Stack is new Table.Table (
114 Table_Component_Type => Nat,
115 Table_Index_Type => Nat,
116 Table_Low_Bound => 1,
117 Table_Initial => Alloc.Conditional_Stack_Initial,
118 Table_Increment => Alloc.Conditional_Stack_Increment,
119 Table_Name => "Conditional_Stack");
121 function Operand_Has_Warnings_Suppressed (N : Node_Id) return Boolean;
122 -- This function traverses the expression tree represented by the node
123 -- N and determines if any sub-operand is a reference to an entity for
124 -- which the Warnings_Off flag is set. True is returned if such an
125 -- entity is encountered, and False otherwise.
127 ----------------------
128 -- Check_References --
129 ----------------------
131 procedure Check_References (E : Entity_Id; Anod : Node_Id := Empty) is
136 procedure Output_Reference_Error (M : String);
137 -- Used to output an error message. Deals with posting the error on
138 -- the body formal in the accept case.
140 function Publicly_Referenceable (Ent : Entity_Id) return Boolean;
141 -- This is true if the entity in question is potentially referenceable
142 -- from another unit. This is true for entities in packages that are
143 -- at the library level.
145 ----------------------------
146 -- Output_Reference_Error --
147 ----------------------------
149 procedure Output_Reference_Error (M : String) is
151 -- Other than accept case, post error on defining identifier
156 -- Accept case, find body formal to post the message
167 if Present (Parameter_Specifications (Anod)) then
168 Parm := First (Parameter_Specifications (Anod));
170 while Present (Parm) loop
171 Defid := Defining_Identifier (Parm);
173 if Chars (E1) = Chars (Defid) then
182 Error_Msg_NE (M, Enod, E1);
185 end Output_Reference_Error;
187 ----------------------------
188 -- Publicly_Referenceable --
189 ----------------------------
191 function Publicly_Referenceable (Ent : Entity_Id) return Boolean is
195 -- Examine parents to look for a library level package spec
196 -- But if we find a body or block or other similar construct
197 -- along the way, we cannot be referenced.
203 -- If we get to top of tree, then publicly referencable
208 -- If we reach a generic package declaration, then always
209 -- consider this referenceable, since any instantiation will
210 -- have access to the entities in the generic package. Note
211 -- that the package itself may not be instantiated, but then
212 -- we will get a warning for the package entity
214 when N_Generic_Package_Declaration =>
217 -- If we reach any body, then definitely not referenceable
219 when N_Package_Body |
228 -- For all other cases, keep looking up tree
234 end Publicly_Referenceable;
236 -- Start of processing for Check_References
239 -- No messages if warnings are suppressed, or if we have detected
240 -- any real errors so far (this last check avoids junk messages
241 -- resulting from errors, e.g. a subunit that is not loaded).
243 -- We also skip the messages if any subunits were not loaded (see
244 -- comment in Sem_Ch10 to understand how this is set, and why it is
245 -- necessary to suppress the warnings in this case).
247 if Warning_Mode = Suppress
248 or else Serious_Errors_Detected /= 0
249 or else Unloaded_Subunits
254 -- Otherwise loop through entities, looking for suspicious stuff
256 E1 := First_Entity (E);
257 while Present (E1) loop
259 -- We only look at source entities with warning flag off
261 if Comes_From_Source (E1) and then not Warnings_Off (E1) then
263 -- We are interested in variables and out parameters, but we
264 -- exclude protected types, too complicated to worry about.
266 if Ekind (E1) = E_Variable
268 (Ekind (E1) = E_Out_Parameter
269 and then not Is_Protected_Type (Current_Scope))
271 -- Post warning if this object not assigned. Note that we
272 -- do not consider the implicit initialization of an access
273 -- type to be the assignment of a value for this purpose.
274 -- If the entity is an out parameter of the current subprogram
275 -- body, check the warning status of the parameter in the spec.
277 if Ekind (E1) = E_Out_Parameter
278 and then Present (Spec_Entity (E1))
279 and then Warnings_Off (Spec_Entity (E1))
283 elsif Not_Source_Assigned (E1) then
284 Output_Reference_Error ("& is never assigned a value?");
286 -- Deal with special case where this variable is hidden
287 -- by a loop variable
289 if Ekind (E1) = E_Variable
290 and then Present (Hiding_Loop_Variable (E1))
292 Error_Msg_Sloc := Sloc (E1);
294 ("declaration hides &#?",
295 Hiding_Loop_Variable (E1));
297 ("for loop implicitly declares loop variable?",
298 Hiding_Loop_Variable (E1));
304 -- Check for unset reference, note that we exclude access
305 -- types from this check, since access types do always have
306 -- a null value, and that seems legitimate in this case.
308 UR := Unset_Reference (E1);
311 -- For access types, the only time we complain is when
312 -- we have a dereference (of a null value)
314 if Is_Access_Type (Etype (E1)) then
317 if (Nkind (PU) = N_Selected_Component
319 Nkind (PU) = N_Explicit_Dereference
321 Nkind (PU) = N_Indexed_Component)
325 Error_Msg_N ("& may be null?", UR);
329 -- For other than access type, go back to original node
330 -- to deal with case where original unset reference
331 -- has been rewritten during expansion.
334 UR := Original_Node (UR);
336 -- In some cases, the original node may be a type
337 -- conversion or qualification, and in this case
338 -- we want the object entity inside.
340 while Nkind (UR) = N_Type_Conversion
341 or else Nkind (UR) = N_Qualified_Expression
343 UR := Expression (UR);
347 ("& may be referenced before it has a value?", UR);
353 -- Then check for unreferenced variables
355 if not Referenced (E1)
357 -- Check that warnings on unreferenced entities are enabled
359 and then ((Check_Unreferenced and then not Is_Formal (E1))
361 (Check_Unreferenced_Formals and then Is_Formal (E1)))
363 -- Warnings are placed on objects, types, subprograms,
364 -- labels, and enumeration literals.
366 and then (Is_Object (E1)
372 Ekind (E1) = E_Named_Integer
374 Ekind (E1) = E_Named_Real
376 Is_Overloadable (E1))
378 -- We only place warnings for the extended main unit
380 and then In_Extended_Main_Source_Unit (E1)
382 -- Exclude instantiations, since there is no reason why
383 -- every entity in an instantiation should be referenced.
385 and then Instantiation_Location (Sloc (E1)) = No_Location
387 -- Exclude formal parameters from bodies if the corresponding
388 -- spec entity has been referenced in the case where there is
391 and then not (Is_Formal (E1)
393 Ekind (Scope (E1)) = E_Subprogram_Body
395 Present (Spec_Entity (E1))
397 Referenced (Spec_Entity (E1)))
399 -- Consider private type referenced if full view is referenced
401 and then not (Is_Private_Type (E1)
403 Referenced (Full_View (E1)))
405 -- Don't worry about full view, only about private type
407 and then not Has_Private_Declaration (E1)
409 -- Eliminate dispatching operations from consideration, we
410 -- cannot tell if these are referenced or not in any easy
411 -- manner (note this also catches Adjust/Finalize/Initialize)
413 and then not Is_Dispatching_Operation (E1)
415 -- Check entity that can be publicly referenced (we do not
416 -- give messages for such entities, since there could be
417 -- other units, not involved in this compilation, that
418 -- contain relevant references.
420 and then not Publicly_Referenceable (E1)
422 -- Class wide types are marked as source entities, but
423 -- they are not really source entities, and are always
424 -- created, so we do not care if they are not referenced.
426 and then Ekind (E1) /= E_Class_Wide_Type
428 -- Objects other than parameters of task types are allowed
429 -- to be non-referenced, since they start up tasks!
431 and then ((Ekind (E1) /= E_Variable
432 and then Ekind (E1) /= E_Constant
433 and then Ekind (E1) /= E_Component)
434 or else not Is_Task_Type (Etype (E1)))
436 -- For subunits, only place warnings on the main unit
437 -- itself, since parent units are not completely compiled
439 and then (Nkind (Unit (Cunit (Main_Unit))) /= N_Subunit
441 Get_Source_Unit (E1) = Main_Unit)
443 -- Suppress warnings in internal units if not in -gnatg
444 -- mode (these would be junk warnings for an applications
445 -- program, since they refer to problems in internal units)
449 Is_Internal_File_Name
450 (Unit_File_Name (Get_Source_Unit (E1)))
452 -- We do not immediately flag the error. This is because
453 -- we have not expanded generic bodies yet, and they may
454 -- have the missing reference. So instead we park the
455 -- entity on a list, for later processing. However, for
456 -- the accept case, post the error right here, since we
457 -- have the information now in this case.
459 if Present (Anod) then
460 Output_Reference_Error ("& is not referenced?");
463 Unreferenced_Entities.Increment_Last;
464 Unreferenced_Entities.Table
465 (Unreferenced_Entities.Last) := E1;
471 -- Recurse into nested package or block
474 if (Ekind (E1) = E_Package
475 and then Nkind (Parent (E1)) = N_Package_Specification)
476 or else Ekind (E1) = E_Block
478 Check_References (E1);
483 end Check_References;
485 ---------------------------
486 -- Check_Unset_Reference --
487 ---------------------------
489 procedure Check_Unset_Reference (N : Node_Id) is
491 -- Nothing to do if warnings suppressed
493 if Warning_Mode = Suppress then
497 -- Otherwise see what kind of node we have. If the entity already
498 -- has an unset reference, it is not necessarily the earliest in
499 -- the text, because resolution of the prefix of selected components
500 -- is completed before the resolution of the selected component itself.
501 -- as a result, given (R /= null and then R.X > 0), the occurrences
502 -- of R are examined in right-to-left order. If there is already an
503 -- unset reference, we check whether N is earlier before proceeding.
507 when N_Identifier | N_Expanded_Name =>
509 E : constant Entity_Id := Entity (N);
512 if (Ekind (E) = E_Variable
513 or else Ekind (E) = E_Out_Parameter)
514 and then Not_Source_Assigned (E)
515 and then (No (Unset_Reference (E))
516 or else Earlier_In_Extended_Unit
517 (Sloc (N), Sloc (Unset_Reference (E))))
518 and then not Warnings_Off (E)
520 -- Here we have a potential unset reference. But before we
521 -- get worried about it, we have to make sure that the
522 -- entity declaration is in the same procedure as the
523 -- reference, since if they are in separate procedures,
524 -- then we have no idea about sequential execution.
526 -- The tests in the loop below catch all such cases, but
527 -- do allow the reference to appear in a loop, block, or
528 -- package spec that is nested within the declaring scope.
529 -- As always, it is possible to construct cases where the
530 -- warning is wrong, that is why it is a warning!
532 -- If the entity is an out_parameter, it is ok to read its
533 -- its discriminants (that was true in Ada83) so suppress
534 -- the message in that case as well.
536 if Ekind (E) = E_Out_Parameter
537 and then Nkind (Parent (N)) = N_Selected_Component
538 and then Ekind (Entity (Selector_Name (Parent (N))))
546 SE : constant Entity_Id := Scope (E);
551 if SR = Standard_Standard
552 or else Is_Subprogram (SR)
553 or else Is_Concurrent_Body (SR)
554 or else Is_Concurrent_Type (SR)
562 if Nkind (N) = N_Identifier then
563 Set_Unset_Reference (E, N);
565 Set_Unset_Reference (E, Selector_Name (N));
571 when N_Indexed_Component | N_Selected_Component | N_Slice =>
572 Check_Unset_Reference (Prefix (N));
575 when N_Type_Conversion | N_Qualified_Expression =>
576 Check_Unset_Reference (Expression (N));
582 end Check_Unset_Reference;
584 ------------------------
585 -- Check_Unused_Withs --
586 ------------------------
588 procedure Check_Unused_Withs (Spec_Unit : Unit_Number_Type := No_Unit) is
594 Munite : constant Entity_Id := Cunit_Entity (Main_Unit);
595 -- This is needed for checking the special renaming case
597 procedure Check_One_Unit (Unit : Unit_Number_Type);
598 -- Subsidiary procedure, performs checks for specified unit
604 procedure Check_One_Unit (Unit : Unit_Number_Type) is
605 Is_Visible_Renaming : Boolean := False;
608 function Find_Package_Renaming
610 L : Entity_Id) return Entity_Id;
611 -- The only reference to a context unit may be in a renaming
612 -- declaration. If this renaming declares a visible entity, do
613 -- not warn that the context clause could be moved to the body,
614 -- because the renaming may be intented to re-export the unit.
616 ---------------------------
617 -- Find_Package_Renaming --
618 ---------------------------
620 function Find_Package_Renaming
622 L : Entity_Id) return Entity_Id
628 Is_Visible_Renaming := False;
629 E1 := First_Entity (P);
631 while Present (E1) loop
632 if Ekind (E1) = E_Package
633 and then Renamed_Object (E1) = L
635 Is_Visible_Renaming := not Is_Hidden (E1);
638 elsif Ekind (E1) = E_Package
639 and then No (Renamed_Object (E1))
640 and then not Is_Generic_Instance (E1)
642 R := Find_Package_Renaming (E1, L);
645 Is_Visible_Renaming := not Is_Hidden (R);
654 end Find_Package_Renaming;
656 -- Start of processing for Check_One_Unit
659 Cnode := Cunit (Unit);
661 -- Only do check in units that are part of the extended main
662 -- unit. This is actually a necessary restriction, because in
663 -- the case of subprogram acting as its own specification,
664 -- there can be with's in subunits that we will not see.
666 if not In_Extended_Main_Source_Unit (Cnode) then
669 -- In No_Run_Time_Mode, we remove the bodies of non-
670 -- inlined subprograms, which may lead to spurious
671 -- warnings, clearly undesirable.
674 and then Is_Predefined_File_Name (Unit_File_Name (Unit))
679 -- Loop through context items in this unit
681 Item := First (Context_Items (Cnode));
682 while Present (Item) loop
684 if Nkind (Item) = N_With_Clause
685 and then not Implicit_With (Item)
686 and then In_Extended_Main_Source_Unit (Item)
688 Lunit := Entity (Name (Item));
690 -- Check if this unit is referenced
692 if not Referenced (Lunit) then
694 -- Suppress warnings in internal units if not in -gnatg
695 -- mode (these would be junk warnings for an applications
696 -- program, since they refer to problems in internal units)
699 or else not Is_Internal_File_Name (Unit_File_Name (Unit))
701 -- Here we definitely have a non-referenced unit. If
702 -- it is the special call for a spec unit, then just
703 -- set the flag to be read later.
705 if Unit = Spec_Unit then
706 Set_Unreferenced_In_Spec (Item);
708 -- Otherwise simple unreferenced message
712 ("unit& is not referenced?", Name (Item));
716 -- If main unit is a renaming of this unit, then we consider
717 -- the with to be OK (obviously it is needed in this case!)
719 elsif Present (Renamed_Entity (Munite))
720 and then Renamed_Entity (Munite) = Lunit
724 -- If this unit is referenced, and it is a package, we
725 -- do another test, to see if any of the entities in the
726 -- package are referenced. If none of the entities are
727 -- referenced, we still post a warning. This occurs if
728 -- the only use of the package is in a use clause, or
729 -- in a package renaming declaration.
731 elsif Ekind (Lunit) = E_Package then
733 -- If Is_Instantiated is set, it means that the package
734 -- is implicitly instantiated (this is the case of a
735 -- parent instance or an actual for a generic package
736 -- formal), and this counts as a reference.
738 if Is_Instantiated (Lunit) then
741 -- If no entities in package, and there is a pragma
742 -- Elaborate_Body present, then assume that this with
743 -- is done for purposes of this elaboration.
745 elsif No (First_Entity (Lunit))
746 and then Has_Pragma_Elaborate_Body (Lunit)
750 -- Otherwise see if any entities have been referenced
753 Ent := First_Entity (Lunit);
756 -- No more entities, and we did not find one
757 -- that was referenced. Means we have a definite
758 -- case of a with none of whose entities was
763 -- If in spec, just set the flag
765 if Unit = Spec_Unit then
766 Set_No_Entities_Ref_In_Spec (Item);
768 -- Else give the warning
772 ("no entities of & are referenced?",
775 -- Look for renamings of this package, and
776 -- flag them as well. If the original package
777 -- has warnings off, we suppress the warning
778 -- on the renaming as well.
780 Pack := Find_Package_Renaming (Munite, Lunit);
783 and then not Warnings_Off (Lunit)
786 ("no entities of & are referenced?",
787 Unit_Declaration_Node (Pack),
794 -- Case of next entity is referenced
796 elsif Referenced (Ent) then
798 -- This means that the with is indeed fine, in
799 -- that it is definitely needed somewhere, and
800 -- we can quite worrying about this one.
802 -- Except for one little detail, if either of
803 -- the flags was set during spec processing,
804 -- this is where we complain that the with
805 -- could be moved from the spec. If the spec
806 -- contains a visible renaming of the package,
807 -- inhibit warning to move with_clause to body.
809 if Ekind (Munite) = E_Package_Body then
811 Find_Package_Renaming
812 (Spec_Entity (Munite), Lunit);
815 if Unreferenced_In_Spec (Item) then
817 ("unit& is not referenced in spec?",
820 elsif No_Entities_Ref_In_Spec (Item) then
822 ("no entities of & are referenced in spec?",
829 if not Is_Visible_Renaming then
831 ("\with clause might be moved to body?",
837 -- Move to next entity to continue search
845 -- For a generic package, the only interesting kind of
846 -- reference is an instantiation, since entities cannot
847 -- be referenced directly.
849 elsif Is_Generic_Unit (Lunit) then
851 -- Unit was never instantiated, set flag for case of spec
852 -- call, or give warning for normal call.
854 if not Is_Instantiated (Lunit) then
855 if Unit = Spec_Unit then
856 Set_Unreferenced_In_Spec (Item);
859 ("unit& is never instantiated?", Name (Item));
862 -- If unit was indeed instantiated, make sure that
863 -- flag is not set showing it was uninstantiated in
864 -- the spec, and if so, give warning.
866 elsif Unreferenced_In_Spec (Item) then
868 ("unit& is not instantiated in spec?", Name (Item));
870 ("\with clause can be moved to body?", Name (Item));
880 -- Start of processing for Check_Unused_Withs
883 if not Opt.Check_Withs
884 or else Operating_Mode = Check_Syntax
889 -- Flag any unused with clauses, but skip this step if we are
890 -- compiling a subunit on its own, since we do not have enough
891 -- information to determine whether with's are used. We will get
892 -- the relevant warnings when we compile the parent. This is the
893 -- normal style of GNAT compilation in any case.
895 if Nkind (Unit (Cunit (Main_Unit))) = N_Subunit then
899 -- Process specified units
901 if Spec_Unit = No_Unit then
903 -- For main call, check all units
905 for Unit in Main_Unit .. Last_Unit loop
906 Check_One_Unit (Unit);
910 -- For call for spec, check only the spec
912 Check_One_Unit (Spec_Unit);
914 end Check_Unused_Withs;
916 -------------------------------------
917 -- Operand_Has_Warnings_Suppressed --
918 -------------------------------------
920 function Operand_Has_Warnings_Suppressed (N : Node_Id) return Boolean is
922 function Check_For_Warnings (N : Node_Id) return Traverse_Result;
923 -- Function used to check one node to see if it is or was originally
924 -- a reference to an entity for which Warnings are off. If so, Abandon
925 -- is returned, otherwise OK_Orig is returned to continue the traversal
926 -- of the original expression.
928 function Traverse is new Traverse_Func (Check_For_Warnings);
929 -- Function used to traverse tree looking for warnings
931 ------------------------
932 -- Check_For_Warnings --
933 ------------------------
935 function Check_For_Warnings (N : Node_Id) return Traverse_Result is
936 R : constant Node_Id := Original_Node (N);
939 if Nkind (R) in N_Has_Entity
940 and then Present (Entity (R))
941 and then Warnings_Off (Entity (R))
947 end Check_For_Warnings;
949 -- Start of processing for Operand_Has_Warnings_Suppressed
952 return Traverse (N) = Abandon;
954 -- If any exception occurs, then something has gone wrong, and this is
955 -- only a minor aesthetic issue anyway, so just say we did not find what
956 -- we are looking for, rather than blow up.
961 end Operand_Has_Warnings_Suppressed;
963 ----------------------------------
964 -- Output_Unreferenced_Messages --
965 ----------------------------------
967 procedure Output_Unreferenced_Messages is
971 for J in Unreferenced_Entities.First ..
972 Unreferenced_Entities.Last
974 E := Unreferenced_Entities.Table (J);
976 if not Referenced (E) and then not Warnings_Off (E) then
980 if Present (Renamed_Object (E))
981 and then Comes_From_Source (Renamed_Object (E))
983 Error_Msg_N ("renamed variable & is not referenced?", E);
985 Error_Msg_N ("variable & is not referenced?", E);
989 if Present (Renamed_Object (E))
990 and then Comes_From_Source (Renamed_Object (E))
992 Error_Msg_N ("renamed constant & is not referenced?", E);
994 Error_Msg_N ("constant & is not referenced?", E);
997 when E_In_Parameter |
999 E_In_Out_Parameter =>
1001 -- Do not emit message for formals of a renaming, because
1002 -- they are never referenced explicitly.
1004 if Nkind (Original_Node (Unit_Declaration_Node (Scope (E))))
1005 /= N_Subprogram_Renaming_Declaration
1007 Error_Msg_N ("formal parameter & is not referenced?", E);
1010 when E_Named_Integer |
1012 Error_Msg_N ("named number & is not referenced?", E);
1014 when E_Enumeration_Literal =>
1015 Error_Msg_N ("literal & is not referenced?", E);
1018 Error_Msg_N ("function & is not referenced?", E);
1021 Error_Msg_N ("procedure & is not referenced?", E);
1024 Error_Msg_N ("type & is not referenced?", E);
1027 Error_Msg_N ("& is not referenced?", E);
1030 Set_Warnings_Off (E);
1033 end Output_Unreferenced_Messages;
1035 -----------------------------
1036 -- Warn_On_Known_Condition --
1037 -----------------------------
1039 procedure Warn_On_Known_Condition (C : Node_Id) is
1043 if Constant_Condition_Warnings
1044 and then Nkind (C) = N_Identifier
1046 (Entity (C) = Standard_False or else Entity (C) = Standard_True)
1047 and then Comes_From_Source (Original_Node (C))
1048 and then not In_Instance
1050 -- See if this is in a statement or a declaration
1054 -- If tree is not attached, do not issue warning (this is very
1055 -- peculiar, and probably arises from some other error condition)
1060 -- If we are in a declaration, then no warning, since in practice
1061 -- conditionals in declarations are used for intended tests which
1062 -- may be known at compile time, e.g. things like
1064 -- x : constant Integer := 2 + (Word'Size = 32);
1066 -- And a warning is annoying in such cases
1068 elsif Nkind (P) in N_Declaration
1070 Nkind (P) in N_Later_Decl_Item
1074 -- Don't warn in assert pragma, since presumably tests in such
1075 -- a context are very definitely intended, and might well be
1076 -- known at compile time. Note that we have to test the original
1077 -- node, since assert pragmas get rewritten at analysis time.
1079 elsif Nkind (Original_Node (P)) = N_Pragma
1080 and then Chars (Original_Node (P)) = Name_Assert
1085 exit when Is_Statement (P);
1089 -- Here we issue the warning unless some sub-operand has warnings
1090 -- set off, in which case we suppress the warning for the node.
1092 if not Operand_Has_Warnings_Suppressed (C) then
1093 if Entity (C) = Standard_True then
1094 Error_Msg_N ("condition is always True?", C);
1096 Error_Msg_N ("condition is always False?", C);
1100 end Warn_On_Known_Condition;