bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] clang Warning - revisited


From: Juergen Sauermann
Subject: Re: [Bug-apl] clang Warning - revisited
Date: Sun, 20 Apr 2014 11:54:53 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130330 Thunderbird/17.0.5

Hi Vladimir,

I see. My point was just that the text of the warning, i.e. "comparison is always true" is wrong because it is, IMHO, not. And I hope that the optimizer in the compiler does
not make the same assumption because that would lead to incorrect code.

/// Jürgen


On 04/20/2014 10:47 AM, Vladimir Ur wrote:
Juergen, I think whis warning is neither about compiler nor c standard.
It is about programmers' convention to use enum type to hold limited set
of values. Using enum for integer is not tricking the compiler, but
tricking other programmers who follow this convention (or even the self).
Most compilers warn if you retreat 'informal' programming rules, because
in most cases this lead to erroneous code.
Formally you do not need to follow this, of course.


On Sat, 19 Apr 2014 14:37:53 +0200
Juergen Sauermann <address@hidden> wrote:

Hi Peter,

I have changed it in SVN 215.

I still disagree with the warning because in a comparison of an
enumeration member
with an integer should perform integer promotion of the enum member to
int and then do
integer comparison and NOT convert the int to an enum member (which it
can't) and then
do the comparison (or issue the warning).

In other words, I read "l < 10" as "(int)l < 10" (which can be true or
false) and not as "l < (Function_line)10"
which can also be true or false because if I allow implicit
(Function_line)10 then I cannot rule out (Function_line)42
either.

The really interesting question is if the compiler would optimize "if (i
< 10)" away which I would consider a fault
in the compiler. As a warning it is just a bit annoying because it
forces "default: ;" all over the place.

/// Jürgen



On 04/19/2014 02:36 AM, Peter Teeson wrote:
Hi Jürgen:

I've been thinking again about this warning and I'm inclined to agree
with it.

..MyProjects/GNUAPL/apl-svn/src/UserFunction.cc:1191:10: Comparison of
constant 10 with expression of type 'Function_Line' is always true

if (l < 10) ucs.append(UNI_ASCII_SPACE);


These suggestions eliminate the Warning.

In File APL_Types.hh

enum Function_Line
{
Function_Retry  = -2, // →'' in immediate execution
Function_Line_0 = 0,
Function_Line_1 = 1,
  Function_Line_MAX = 10  // << === My suggestion
};

In UserFunction.cc:1191:10:
if (l < Function_Line_MAX)   ucs.append(UNI_ASCII_SPACE); // << === My
suggestion






reply via email to

[Prev in Thread] Current Thread [Next in Thread]