octave-maintainers
[Top][All Lists]
Advanced

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

Re: warning: suggest parenthesis around assignment used as truth value


From: Ben Abbott
Subject: Re: warning: suggest parenthesis around assignment used as truth value
Date: Fri, 13 Mar 2009 10:48:37 +0800


On Mar 13, 2009, at 9:40 AM, Rob Mahurin wrote:

On Mar 12, 2009, at 9:08 PM, Ben Abbott wrote:
Can someone explain what this warning is intended to imply?

        warning: suggest parenthesis around assignment used as truth value

This is a gcc warning? The idiom
        if (x=1) { ... }
is legal and useful but often a typo for
        if (x==1) { ... }
Extra parentheses
        if ((x=1)) { ... }
apparently suppress the warning.

Cheers,
Rob

Actually, it is a warning form Octave's parser (the source is an m- file). The warning originates in parse.y

1506 // Maybe print a warning if an assignment expression is used as the
1507 // test in a logical expression.
1508
1509 static void
1510 maybe_warn_assign_as_truth_value (tree_expression *expr)
1511 {
1512   if (expr->is_assignment_expression ()
1513       && expr->paren_count () < 2)
1514     {
1515       warning_with_id
1516         ("Octave:assign-as-truth-value",
1517 "suggest parenthesis around assignment used as truth value");
1518     }
1519 }

Your examples do give me some additional context for what is imlied. Unfortunately, I've searched my sources and don't see such an instance in my if/elseif statments. Further when I convert warnings to errors ("warning error"), I get what looks like a parser error.

octave:1> warning error
octave:2> help cellstr
error: potential auto-insertion of `,' near line 47 of file /Users/ bpabbott/Development/mercurial/octave-3.1.54/scripts/help/which.m
error: called from:
error: /Users/bpabbott/Development/mercurial/octave-3.1.54/scripts/ help/help.m at line 81, column 5
octave:2> help test
error: potential auto-insertion of `,' near line 89 of file /Users/ bpabbott/Development/mercurial/octave-3.1.54/scripts/strings/strcat.m
error: called from:
error: /Users/bpabbott/Development/mercurial/octave-3.1.54/scripts/ help/__makeinfo__.m at line 154, column 12 error: /Users/bpabbott/Development/mercurial/octave-3.1.54/scripts/ help/__makeinfo__.m at line 111, column 16 error: /Users/bpabbott/Development/mercurial/octave-3.1.54/scripts/ help/help.m at line 62, column 25
octave:2>

I'll start a new thread for that.

Ben



reply via email to

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