1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1999-2002 Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
26 ------------------------------------------------------------------------------
29 with Atree; use Atree;
30 with Einfo; use Einfo;
31 with Errout; use Errout;
32 with Fname; use Fname;
34 with Nlists; use Nlists;
37 with Sem_Util; use Sem_Util;
38 with Sinfo; use Sinfo;
39 with Sinput; use Sinput;
40 with Snames; use Snames;
41 with Stand; use Stand;
44 package body Sem_Warn is
46 -- The following table collects Id's of entities that are potentially
47 -- unreferenced. See Check_Unset_Reference for further details.
49 package Unreferenced_Entities is new Table.Table (
50 Table_Component_Type => Entity_Id,
51 Table_Index_Type => Nat,
53 Table_Initial => Alloc.Unreferenced_Entities_Initial,
54 Table_Increment => Alloc.Unreferenced_Entities_Increment,
55 Table_Name => "Unreferenced_Entities");
57 -- One entry is made in the following table for each branch of
58 -- a conditional, e.g. an if-then-elsif-else-endif structure
59 -- creates three entries in this table.
61 type Branch_Entry is record
63 -- Location for warnings associated with this branch
66 -- List of entities defined for the first time in this branch. On
67 -- exit from a conditional structure, any entity that is in the
68 -- list of all branches is removed (and the entity flagged as
69 -- defined by the conditional as a whole). Thus after processing
70 -- a conditional, Defs contains a list of entities defined in this
71 -- branch for the first time, but not defined at all in some other
72 -- branch of the same conditional. A value of No_Elist is used to
73 -- represent the initial empty list.
76 -- Index of next branch for this conditional, zero = last branch
79 package Branch_Table is new Table.Table (
80 Table_Component_Type => Branch_Entry,
81 Table_Index_Type => Nat,
83 Table_Initial => Alloc.Branches_Initial,
84 Table_Increment => Alloc.Branches_Increment,
85 Table_Name => "Branches");
87 -- The following table is used to represent conditionals, there is
88 -- one entry in this table for each conditional structure.
90 type Conditional_Entry is record
92 -- True for IF statement, False for CASE statement
95 -- Index in Branch table of first branch, zero = none yet
98 -- Index in Branch table of current branch, zero = none yet
101 package Conditional_Table is new Table.Table (
102 Table_Component_Type => Conditional_Entry,
103 Table_Index_Type => Nat,
104 Table_Low_Bound => 1,
105 Table_Initial => Alloc.Conditionals_Initial,
106 Table_Increment => Alloc.Conditionals_Increment,
107 Table_Name => "Conditionals");
109 -- The following table is a stack that keeps track of the current
110 -- conditional. The Last entry is the top of the stack. An Empty
111 -- entry represents the start of a compilation unit. Non-zero
112 -- entries in the stack are indexes into the conditional table.
114 package Conditional_Stack is new Table.Table (
115 Table_Component_Type => Nat,
116 Table_Index_Type => Nat,
117 Table_Low_Bound => 1,
118 Table_Initial => Alloc.Conditional_Stack_Initial,
119 Table_Increment => Alloc.Conditional_Stack_Increment,
120 Table_Name => "Conditional_Stack");
122 function Operand_Has_Warnings_Suppressed (N : Node_Id) return Boolean;
123 -- This function traverses the expression tree represented by the node
124 -- N and determines if any sub-operand is a reference to an entity for
125 -- which the Warnings_Off flag is set. True is returned if such an
126 -- entity is encountered, and False otherwise.
128 ----------------------
129 -- Check_References --
130 ----------------------
132 procedure Check_References (E : Entity_Id; Anod : Node_Id := Empty) is
137 procedure Output_Reference_Error (M : String);
138 -- Used to output an error message. Deals with posting the error on
139 -- the body formal in the accept case.
141 function Publicly_Referenceable (Ent : Entity_Id) return Boolean;
142 -- This is true if the entity in question is potentially referenceable
143 -- from another unit. This is true for entities in packages that are
144 -- at the library level.
146 ----------------------------
147 -- Output_Reference_Error --
148 ----------------------------
150 procedure Output_Reference_Error (M : String) is
152 -- Other than accept case, post error on defining identifier
157 -- Accept case, find body formal to post the message
168 if Present (Parameter_Specifications (Anod)) then
169 Parm := First (Parameter_Specifications (Anod));
171 while Present (Parm) loop
172 Defid := Defining_Identifier (Parm);
174 if Chars (E1) = Chars (Defid) then
183 Error_Msg_NE (M, Enod, E1);
186 end Output_Reference_Error;
188 ----------------------------
189 -- Publicly_Referenceable --
190 ----------------------------
192 function Publicly_Referenceable (Ent : Entity_Id) return Boolean is
196 -- Examine parents to look for a library level package spec
197 -- But if we find a body or block or other similar construct
198 -- along the way, we cannot be referenced.
204 -- If we get to top of tree, then publicly referencable
209 -- If we reach a generic package declaration, then always
210 -- consider this referenceable, since any instantiation will
211 -- have access to the entities in the generic package. Note
212 -- that the package itself may not be instantiated, but then
213 -- we will get a warning for the package entity
215 when N_Generic_Package_Declaration =>
218 -- If we reach any body, then definitely not referenceable
220 when N_Package_Body |
229 -- For all other cases, keep looking up tree
235 end Publicly_Referenceable;
237 -- Start of processing for Check_References
240 -- No messages if warnings are suppressed, or if we have detected
241 -- any real errors so far (this last check avoids junk messages
242 -- resulting from errors, e.g. a subunit that is not loaded).
244 -- We also skip the messages if any subunits were not loaded (see
245 -- comment in Sem_Ch10 to understand how this is set, and why it is
246 -- necessary to suppress the warnings in this case).
248 if Warning_Mode = Suppress
249 or else Serious_Errors_Detected /= 0
250 or else Unloaded_Subunits
255 -- Otherwise loop through entities, looking for suspicious stuff
257 E1 := First_Entity (E);
258 while Present (E1) loop
260 -- We only look at source entities with warning flag off
262 if Comes_From_Source (E1) and then not Warnings_Off (E1) then
264 -- We are interested in variables and out parameters, but we
265 -- exclude protected types, too complicated to worry about.
267 if Ekind (E1) = E_Variable
269 (Ekind (E1) = E_Out_Parameter
270 and then not Is_Protected_Type (Current_Scope))
272 -- Post warning if this object not assigned. Note that we
273 -- do not consider the implicit initialization of an access
274 -- type to be the assignment of a value for this purpose.
275 -- If the entity is an out parameter of the current subprogram
276 -- body, check the warning status of the parameter in the spec.
278 if Ekind (E1) = E_Out_Parameter
279 and then Present (Spec_Entity (E1))
280 and then Warnings_Off (Spec_Entity (E1))
284 elsif Not_Source_Assigned (E1) then
285 Output_Reference_Error ("& is never assigned a value?");
287 -- Deal with special case where this variable is hidden
288 -- by a loop variable
290 if Ekind (E1) = E_Variable
291 and then Present (Hiding_Loop_Variable (E1))
293 Error_Msg_Sloc := Sloc (E1);
295 ("declaration hides &#?",
296 Hiding_Loop_Variable (E1));
298 ("for loop implicitly declares loop variable?",
299 Hiding_Loop_Variable (E1));
305 -- Check for unset reference, note that we exclude access
306 -- types from this check, since access types do always have
307 -- a null value, and that seems legitimate in this case.
309 UR := Unset_Reference (E1);
312 -- For access types, the only time we complain is when
313 -- we have a dereference (of a null value)
315 if Is_Access_Type (Etype (E1)) then
318 if (Nkind (PU) = N_Selected_Component
320 Nkind (PU) = N_Explicit_Dereference
322 Nkind (PU) = N_Indexed_Component)
326 Error_Msg_N ("& may be null?", UR);
330 -- For other than access type, go back to original node
331 -- to deal with case where original unset reference
332 -- has been rewritten during expansion.
335 UR := Original_Node (UR);
337 -- In some cases, the original node may be a type
338 -- conversion or qualification, and in this case
339 -- we want the object entity inside.
341 while Nkind (UR) = N_Type_Conversion
342 or else Nkind (UR) = N_Qualified_Expression
344 UR := Expression (UR);
348 ("& may be referenced before it has a value?", UR);
354 -- Then check for unreferenced variables
356 if not Referenced (E1)
358 -- Check that warnings on unreferenced entities are enabled
360 and then ((Check_Unreferenced and then not Is_Formal (E1))
362 (Check_Unreferenced_Formals and then Is_Formal (E1)))
364 -- Warnings are placed on objects, types, subprograms,
365 -- labels, and enumeration literals.
367 and then (Is_Object (E1)
373 Ekind (E1) = E_Named_Integer
375 Ekind (E1) = E_Named_Real
377 Is_Overloadable (E1))
379 -- We only place warnings for the extended main unit
381 and then In_Extended_Main_Source_Unit (E1)
383 -- Exclude instantiations, since there is no reason why
384 -- every entity in an instantiation should be referenced.
386 and then Instantiation_Location (Sloc (E1)) = No_Location
388 -- Exclude formal parameters from bodies if the corresponding
389 -- spec entity has been referenced in the case where there is
392 and then not (Is_Formal (E1)
394 Ekind (Scope (E1)) = E_Subprogram_Body
396 Present (Spec_Entity (E1))
398 Referenced (Spec_Entity (E1)))
400 -- Consider private type referenced if full view is referenced
402 and then not (Is_Private_Type (E1)
404 Referenced (Full_View (E1)))
406 -- Don't worry about full view, only about private type
408 and then not Has_Private_Declaration (E1)
410 -- Eliminate dispatching operations from consideration, we
411 -- cannot tell if these are referenced or not in any easy
412 -- manner (note this also catches Adjust/Finalize/Initialize)
414 and then not Is_Dispatching_Operation (E1)
416 -- Check entity that can be publicly referenced (we do not
417 -- give messages for such entities, since there could be
418 -- other units, not involved in this compilation, that
419 -- contain relevant references.
421 and then not Publicly_Referenceable (E1)
423 -- Class wide types are marked as source entities, but
424 -- they are not really source entities, and are always
425 -- created, so we do not care if they are not referenced.
427 and then Ekind (E1) /= E_Class_Wide_Type
429 -- Objects other than parameters of task types are allowed
430 -- to be non-referenced, since they start up tasks!
432 and then ((Ekind (E1) /= E_Variable
433 and then Ekind (E1) /= E_Constant
434 and then Ekind (E1) /= E_Component)
435 or else not Is_Task_Type (Etype (E1)))
437 -- For subunits, only place warnings on the main unit
438 -- itself, since parent units are not completely compiled
440 and then (Nkind (Unit (Cunit (Main_Unit))) /= N_Subunit
442 Get_Source_Unit (E1) = Main_Unit)
444 -- Suppress warnings in internal units if not in -gnatg
445 -- mode (these would be junk warnings for an applications
446 -- program, since they refer to problems in internal units)
450 Is_Internal_File_Name
451 (Unit_File_Name (Get_Source_Unit (E1)))
453 -- We do not immediately flag the error. This is because
454 -- we have not expanded generic bodies yet, and they may
455 -- have the missing reference. So instead we park the
456 -- entity on a list, for later processing. However, for
457 -- the accept case, post the error right here, since we
458 -- have the information now in this case.
460 if Present (Anod) then
461 Output_Reference_Error ("& is not referenced?");
464 Unreferenced_Entities.Increment_Last;
465 Unreferenced_Entities.Table
466 (Unreferenced_Entities.Last) := E1;
472 -- Recurse into nested package or block
475 if (Ekind (E1) = E_Package
476 and then Nkind (Parent (E1)) = N_Package_Specification)
477 or else Ekind (E1) = E_Block
479 Check_References (E1);
484 end Check_References;
486 ---------------------------
487 -- Check_Unset_Reference --
488 ---------------------------
490 procedure Check_Unset_Reference (N : Node_Id) is
492 -- Nothing to do if warnings suppressed
494 if Warning_Mode = Suppress then
498 -- Otherwise see what kind of node we have. If the entity already
499 -- has an unset reference, it is not necessarily the earliest in
500 -- the text, because resolution of the prefix of selected components
501 -- is completed before the resolution of the selected component itself.
502 -- as a result, given (R /= null and then R.X > 0), the occurrences
503 -- of R are examined in right-to-left order. If there is already an
504 -- unset reference, we check whether N is earlier before proceeding.
508 when N_Identifier | N_Expanded_Name =>
510 E : constant Entity_Id := Entity (N);
513 if (Ekind (E) = E_Variable
514 or else Ekind (E) = E_Out_Parameter)
515 and then Not_Source_Assigned (E)
516 and then (No (Unset_Reference (E))
517 or else Earlier_In_Extended_Unit
518 (Sloc (N), Sloc (Unset_Reference (E))))
519 and then not Warnings_Off (E)
521 -- Here we have a potential unset reference. But before we
522 -- get worried about it, we have to make sure that the
523 -- entity declaration is in the same procedure as the
524 -- reference, since if they are in separate procedures,
525 -- then we have no idea about sequential execution.
527 -- The tests in the loop below catch all such cases, but
528 -- do allow the reference to appear in a loop, block, or
529 -- package spec that is nested within the declaring scope.
530 -- As always, it is possible to construct cases where the
531 -- warning is wrong, that is why it is a warning!
533 -- If the entity is an out_parameter, it is ok to read its
534 -- its discriminants (that was true in Ada83) so suppress
535 -- the message in that case as well.
537 if Ekind (E) = E_Out_Parameter
538 and then Nkind (Parent (N)) = N_Selected_Component
539 and then Ekind (Entity (Selector_Name (Parent (N))))
547 SE : constant Entity_Id := Scope (E);
552 if SR = Standard_Standard
553 or else Is_Subprogram (SR)
554 or else Is_Concurrent_Body (SR)
555 or else Is_Concurrent_Type (SR)
563 if Nkind (N) = N_Identifier then
564 Set_Unset_Reference (E, N);
566 Set_Unset_Reference (E, Selector_Name (N));
572 when N_Indexed_Component | N_Selected_Component | N_Slice =>
573 Check_Unset_Reference (Prefix (N));
576 when N_Type_Conversion | N_Qualified_Expression =>
577 Check_Unset_Reference (Expression (N));
583 end Check_Unset_Reference;
585 ------------------------
586 -- Check_Unused_Withs --
587 ------------------------
589 procedure Check_Unused_Withs (Spec_Unit : Unit_Number_Type := No_Unit) is
595 Munite : constant Entity_Id := Cunit_Entity (Main_Unit);
596 -- This is needed for checking the special renaming case
598 procedure Check_One_Unit (Unit : Unit_Number_Type);
599 -- Subsidiary procedure, performs checks for specified unit
605 procedure Check_One_Unit (Unit : Unit_Number_Type) is
606 Is_Visible_Renaming : Boolean := False;
609 function Find_Package_Renaming
611 L : Entity_Id) return Entity_Id;
612 -- The only reference to a context unit may be in a renaming
613 -- declaration. If this renaming declares a visible entity, do
614 -- not warn that the context clause could be moved to the body,
615 -- because the renaming may be intented to re-export the unit.
617 ---------------------------
618 -- Find_Package_Renaming --
619 ---------------------------
621 function Find_Package_Renaming
623 L : Entity_Id) return Entity_Id
629 Is_Visible_Renaming := False;
630 E1 := First_Entity (P);
632 while Present (E1) loop
633 if Ekind (E1) = E_Package
634 and then Renamed_Object (E1) = L
636 Is_Visible_Renaming := not Is_Hidden (E1);
639 elsif Ekind (E1) = E_Package
640 and then No (Renamed_Object (E1))
641 and then not Is_Generic_Instance (E1)
643 R := Find_Package_Renaming (E1, L);
646 Is_Visible_Renaming := not Is_Hidden (R);
655 end Find_Package_Renaming;
657 -- Start of processing for Check_One_Unit
660 Cnode := Cunit (Unit);
662 -- Only do check in units that are part of the extended main
663 -- unit. This is actually a necessary restriction, because in
664 -- the case of subprogram acting as its own specification,
665 -- there can be with's in subunits that we will not see.
667 if not In_Extended_Main_Source_Unit (Cnode) then
670 -- In No_Run_Time_Mode, we remove the bodies of non-
671 -- inlined subprograms, which may lead to spurious
672 -- warnings, clearly undesirable.
675 and then Is_Predefined_File_Name (Unit_File_Name (Unit))
680 -- Loop through context items in this unit
682 Item := First (Context_Items (Cnode));
683 while Present (Item) loop
685 if Nkind (Item) = N_With_Clause
686 and then not Implicit_With (Item)
687 and then In_Extended_Main_Source_Unit (Item)
689 Lunit := Entity (Name (Item));
691 -- Check if this unit is referenced
693 if not Referenced (Lunit) then
695 -- Suppress warnings in internal units if not in -gnatg
696 -- mode (these would be junk warnings for an applications
697 -- program, since they refer to problems in internal units)
700 or else not Is_Internal_File_Name (Unit_File_Name (Unit))
702 -- Here we definitely have a non-referenced unit. If
703 -- it is the special call for a spec unit, then just
704 -- set the flag to be read later.
706 if Unit = Spec_Unit then
707 Set_Unreferenced_In_Spec (Item);
709 -- Otherwise simple unreferenced message
713 ("unit& is not referenced?", Name (Item));
717 -- If main unit is a renaming of this unit, then we consider
718 -- the with to be OK (obviously it is needed in this case!)
720 elsif Present (Renamed_Entity (Munite))
721 and then Renamed_Entity (Munite) = Lunit
725 -- If this unit is referenced, and it is a package, we
726 -- do another test, to see if any of the entities in the
727 -- package are referenced. If none of the entities are
728 -- referenced, we still post a warning. This occurs if
729 -- the only use of the package is in a use clause, or
730 -- in a package renaming declaration.
732 elsif Ekind (Lunit) = E_Package then
734 -- If Is_Instantiated is set, it means that the package
735 -- is implicitly instantiated (this is the case of a
736 -- parent instance or an actual for a generic package
737 -- formal), and this counts as a reference.
739 if Is_Instantiated (Lunit) then
742 -- If no entities in package, and there is a pragma
743 -- Elaborate_Body present, then assume that this with
744 -- is done for purposes of this elaboration.
746 elsif No (First_Entity (Lunit))
747 and then Has_Pragma_Elaborate_Body (Lunit)
751 -- Otherwise see if any entities have been referenced
754 Ent := First_Entity (Lunit);
757 -- No more entities, and we did not find one
758 -- that was referenced. Means we have a definite
759 -- case of a with none of whose entities was
764 -- If in spec, just set the flag
766 if Unit = Spec_Unit then
767 Set_No_Entities_Ref_In_Spec (Item);
769 -- Else give the warning
773 ("no entities of & are referenced?",
776 -- Look for renamings of this package, and
777 -- flag them as well. If the original package
778 -- has warnings off, we suppress the warning
779 -- on the renaming as well.
781 Pack := Find_Package_Renaming (Munite, Lunit);
784 and then not Warnings_Off (Lunit)
787 ("no entities of & are referenced?",
788 Unit_Declaration_Node (Pack),
795 -- Case of next entity is referenced
797 elsif Referenced (Ent) then
799 -- This means that the with is indeed fine, in
800 -- that it is definitely needed somewhere, and
801 -- we can quite worrying about this one.
803 -- Except for one little detail, if either of
804 -- the flags was set during spec processing,
805 -- this is where we complain that the with
806 -- could be moved from the spec. If the spec
807 -- contains a visible renaming of the package,
808 -- inhibit warning to move with_clause to body.
810 if Ekind (Munite) = E_Package_Body then
812 Find_Package_Renaming
813 (Spec_Entity (Munite), Lunit);
816 if Unreferenced_In_Spec (Item) then
818 ("unit& is not referenced in spec?",
821 elsif No_Entities_Ref_In_Spec (Item) then
823 ("no entities of & are referenced in spec?",
830 if not Is_Visible_Renaming then
832 ("\with clause might be moved to body?",
838 -- Move to next entity to continue search
846 -- For a generic package, the only interesting kind of
847 -- reference is an instantiation, since entities cannot
848 -- be referenced directly.
850 elsif Is_Generic_Unit (Lunit) then
852 -- Unit was never instantiated, set flag for case of spec
853 -- call, or give warning for normal call.
855 if not Is_Instantiated (Lunit) then
856 if Unit = Spec_Unit then
857 Set_Unreferenced_In_Spec (Item);
860 ("unit& is never instantiated?", Name (Item));
863 -- If unit was indeed instantiated, make sure that
864 -- flag is not set showing it was uninstantiated in
865 -- the spec, and if so, give warning.
867 elsif Unreferenced_In_Spec (Item) then
869 ("unit& is not instantiated in spec?", Name (Item));
871 ("\with clause can be moved to body?", Name (Item));
881 -- Start of processing for Check_Unused_Withs
884 if not Opt.Check_Withs
885 or else Operating_Mode = Check_Syntax
890 -- Flag any unused with clauses, but skip this step if we are
891 -- compiling a subunit on its own, since we do not have enough
892 -- information to determine whether with's are used. We will get
893 -- the relevant warnings when we compile the parent. This is the
894 -- normal style of GNAT compilation in any case.
896 if Nkind (Unit (Cunit (Main_Unit))) = N_Subunit then
900 -- Process specified units
902 if Spec_Unit = No_Unit then
904 -- For main call, check all units
906 for Unit in Main_Unit .. Last_Unit loop
907 Check_One_Unit (Unit);
911 -- For call for spec, check only the spec
913 Check_One_Unit (Spec_Unit);
915 end Check_Unused_Withs;
917 -------------------------------------
918 -- Operand_Has_Warnings_Suppressed --
919 -------------------------------------
921 function Operand_Has_Warnings_Suppressed (N : Node_Id) return Boolean is
923 function Check_For_Warnings (N : Node_Id) return Traverse_Result;
924 -- Function used to check one node to see if it is or was originally
925 -- a reference to an entity for which Warnings are off. If so, Abandon
926 -- is returned, otherwise OK_Orig is returned to continue the traversal
927 -- of the original expression.
929 function Traverse is new Traverse_Func (Check_For_Warnings);
930 -- Function used to traverse tree looking for warnings
932 ------------------------
933 -- Check_For_Warnings --
934 ------------------------
936 function Check_For_Warnings (N : Node_Id) return Traverse_Result is
937 R : constant Node_Id := Original_Node (N);
940 if Nkind (R) in N_Has_Entity
941 and then Present (Entity (R))
942 and then Warnings_Off (Entity (R))
948 end Check_For_Warnings;
950 -- Start of processing for Operand_Has_Warnings_Suppressed
953 return Traverse (N) = Abandon;
955 -- If any exception occurs, then something has gone wrong, and this is
956 -- only a minor aesthetic issue anyway, so just say we did not find what
957 -- we are looking for, rather than blow up.
962 end Operand_Has_Warnings_Suppressed;
964 ----------------------------------
965 -- Output_Unreferenced_Messages --
966 ----------------------------------
968 procedure Output_Unreferenced_Messages is
972 for J in Unreferenced_Entities.First ..
973 Unreferenced_Entities.Last
975 E := Unreferenced_Entities.Table (J);
977 if not Referenced (E) and then not Warnings_Off (E) then
981 if Present (Renamed_Object (E))
982 and then Comes_From_Source (Renamed_Object (E))
984 Error_Msg_N ("renamed variable & is not referenced?", E);
986 Error_Msg_N ("variable & is not referenced?", E);
990 if Present (Renamed_Object (E))
991 and then Comes_From_Source (Renamed_Object (E))
993 Error_Msg_N ("renamed constant & is not referenced?", E);
995 Error_Msg_N ("constant & is not referenced?", E);
998 when E_In_Parameter |
1000 E_In_Out_Parameter =>
1002 -- Do not emit message for formals of a renaming, because
1003 -- they are never referenced explicitly.
1005 if Nkind (Original_Node (Unit_Declaration_Node (Scope (E))))
1006 /= N_Subprogram_Renaming_Declaration
1008 Error_Msg_N ("formal parameter & is not referenced?", E);
1011 when E_Named_Integer |
1013 Error_Msg_N ("named number & is not referenced?", E);
1015 when E_Enumeration_Literal =>
1016 Error_Msg_N ("literal & is not referenced?", E);
1019 Error_Msg_N ("function & is not referenced?", E);
1022 Error_Msg_N ("procedure & is not referenced?", E);
1025 Error_Msg_N ("type & is not referenced?", E);
1028 Error_Msg_N ("& is not referenced?", E);
1031 Set_Warnings_Off (E);
1034 end Output_Unreferenced_Messages;
1036 -----------------------------
1037 -- Warn_On_Known_Condition --
1038 -----------------------------
1040 procedure Warn_On_Known_Condition (C : Node_Id) is
1044 if Constant_Condition_Warnings
1045 and then Nkind (C) = N_Identifier
1047 (Entity (C) = Standard_False or else Entity (C) = Standard_True)
1048 and then Comes_From_Source (Original_Node (C))
1049 and then not In_Instance
1051 -- See if this is in a statement or a declaration
1055 -- If tree is not attached, do not issue warning (this is very
1056 -- peculiar, and probably arises from some other error condition)
1061 -- If we are in a declaration, then no warning, since in practice
1062 -- conditionals in declarations are used for intended tests which
1063 -- may be known at compile time, e.g. things like
1065 -- x : constant Integer := 2 + (Word'Size = 32);
1067 -- And a warning is annoying in such cases
1069 elsif Nkind (P) in N_Declaration
1071 Nkind (P) in N_Later_Decl_Item
1075 -- Don't warn in assert pragma, since presumably tests in such
1076 -- a context are very definitely intended, and might well be
1077 -- known at compile time. Note that we have to test the original
1078 -- node, since assert pragmas get rewritten at analysis time.
1080 elsif Nkind (Original_Node (P)) = N_Pragma
1081 and then Chars (Original_Node (P)) = Name_Assert
1086 exit when Is_Statement (P);
1090 -- Here we issue the warning unless some sub-operand has warnings
1091 -- set off, in which case we suppress the warning for the node.
1093 if not Operand_Has_Warnings_Suppressed (C) then
1094 if Entity (C) = Standard_True then
1095 Error_Msg_N ("condition is always True?", C);
1097 Error_Msg_N ("condition is always False?", C);
1101 end Warn_On_Known_Condition;