With -gnatwa, GNAT emits very useful warnings; one of them is "condition is
always False".  However, GNAT does not emit this warning when it applies inside
a generic, or a generic instantiation.  The following test case demonstrates
the problem.

procedure Condition_Is_Always_False is

   type T is range 3 .. 4;

   function F return T is
   begin
      return T'First;
   end F;

   procedure OK is
      C : constant T := F;
   begin
      if C = 1 then -- warning: condition is always False
         null;
      end if;
   end OK;

   generic
   procedure NOK_G;

   procedure NOK_G is
      C : constant T := F; -- T'First instead of F gives the warning
   begin
      if C = 1 then -- no warning
         null;
      end if;
   end NOK_G;

   procedure NOK is new NOK_G;

begin -- Condition_Is_Always_False
   OK;
   NOK;
end  Condition_Is_Always_False;

gcc-4.1 -c -gnatwa condition_is_always_false.adb
condition_is_always_false.adb:13:12: warning: condition is always False
gnatbind -x condition_is_always_false.ali
gnatlink condition_is_always_false.ali

If, however, C is initialized directly with T'First (a static value) instead of
the result of F (a static function), GNAT gives the warning even inside the
generic.


-- 
           Summary: "warning: condition is always False" not issued inside
                    generics
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: ada
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ludovic at ludovic-brenta dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35464

Reply via email to