This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Fix wording in constant condition warning


Tested on i686-linux, committed on mainline.

The compiler emits a warning whenever an expression in a condition is
a constant. When the expression is an inequality, it is rewritten as
a negation of equality, and it is the value of the equality that is
reported in the warning. This patch recognizes that the context includes
a negation, and adjusts the message.
test case:
gcc -c -gnatwa static_condition_bug.adb
static_condition_bug.adb:8:16: warning: condition is always True
--
package Static_Condition_Bug is
  type Day is
     (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);
  subtype Weekday is Day range Monday .. Friday;
  procedure F (D_Day : in out Weekday);
end Static_Condition_Bug;
package body Static_Condition_Bug is
   procedure F (D_Day : in out Weekday) is
   begin
      if D_Day /= Sunday then
         D_Day := Tuesday;
      end if;
   end F;
end Static_Condition_Bug;

2005-06-14  Ed Schonberg  <schonberg@adacore.com>

	* sem_warn.adb (Warn_On_Known_Condition): If the constant expression
	appears within a negation (either from source or as a rewriting of
	inequality) adjust text of warning accordingly.

Attachment: difs.50
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]