public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ada/35464]  New: "warning: condition is always False" not issued inside generics
@ 2008-03-04 21:15 ludovic at ludovic-brenta dot org
  2008-03-05  8:35 ` [Bug ada/35464] " sam at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: ludovic at ludovic-brenta dot org @ 2008-03-04 21:15 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug ada/35464] "warning: condition is always False" not issued inside generics
  2008-03-04 21:15 [Bug ada/35464] New: "warning: condition is always False" not issued inside generics ludovic at ludovic-brenta dot org
@ 2008-03-05  8:35 ` sam at gcc dot gnu dot org
  2008-03-05  8:38 ` sam at gcc dot gnu dot org
  2008-05-12 22:39 ` charlet at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: sam at gcc dot gnu dot org @ 2008-03-05  8:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from sam at gcc dot gnu dot org  2008-03-05 08:34 -------
Confirmed on GCC 4.4.0 20080303.

I think this warning is disabled on purpose on instances because you may end up
with conditions being always true or false *in somes instances only*. And in
these cases, you certainly do not want the warning to occur, as the code may be
perfectly legit.

Reinstating the warning in instances would require analyzing whether the
current test depends, directly or indirectly, on generic formal parameters, and
issuing the warning only when there are no dependencies. This would require
quite a lot of work to do it properly.


-- 

sam at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sam at gcc dot gnu dot org
           Severity|minor                       |enhancement
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
      Known to fail|4.1.2 4.3.0                 |4.1.2 4.3.0 4.4.0
           Priority|P3                          |P5
   Last reconfirmed|0000-00-00 00:00:00         |2008-03-05 08:34:58
               date|                            |


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug ada/35464] "warning: condition is always False" not issued inside generics
  2008-03-04 21:15 [Bug ada/35464] New: "warning: condition is always False" not issued inside generics ludovic at ludovic-brenta dot org
  2008-03-05  8:35 ` [Bug ada/35464] " sam at gcc dot gnu dot org
@ 2008-03-05  8:38 ` sam at gcc dot gnu dot org
  2008-05-12 22:39 ` charlet at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: sam at gcc dot gnu dot org @ 2008-03-05  8:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from sam at gcc dot gnu dot org  2008-03-05 08:38 -------
Also note that for the same reason, you will not get a warning from an inlined
body. See sem_warn.adb (Warn_On_Known_Condition).


-- 


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug ada/35464] "warning: condition is always False" not issued inside generics
  2008-03-04 21:15 [Bug ada/35464] New: "warning: condition is always False" not issued inside generics ludovic at ludovic-brenta dot org
  2008-03-05  8:35 ` [Bug ada/35464] " sam at gcc dot gnu dot org
  2008-03-05  8:38 ` sam at gcc dot gnu dot org
@ 2008-05-12 22:39 ` charlet at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: charlet at gcc dot gnu dot org @ 2008-05-12 22:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from charlet at gcc dot gnu dot org  2008-05-12 22:38 -------
Right, this is really as intended, to avoid too many false positives.
The warning circuitry is not prepared to handle more complex cases,
which would require really a different kind of tool, so is out of the scope
of the front-end.

Arno


-- 

charlet at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-05-12 22:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-04 21:15 [Bug ada/35464] New: "warning: condition is always False" not issued inside generics ludovic at ludovic-brenta dot org
2008-03-05  8:35 ` [Bug ada/35464] " sam at gcc dot gnu dot org
2008-03-05  8:38 ` sam at gcc dot gnu dot org
2008-05-12 22:39 ` charlet at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).