<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Missing -Wparentheses warning for assignment withing assert()"
   href="https://bugs.llvm.org/show_bug.cgi?id=47364">47364</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missing -Wparentheses warning for assignment withing assert()
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>10.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mpg@elzevir.fr
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hi,

Consider the following example:

#include <assert.h>

extern int foo(void);

int main(void) {
    int ret = foo();
    assert(ret = 0); // oops
}

Compiled with `clang -Weverything -Werror -std=c99 -pedantic -c` (Clang
version: 10.0.0-4ubuntu1) it doesn't produce any warning.

The line marked "oops" is an actual typo I made in a project, and I would have
been grateful if Clang had given me a warning for it.

In fact, considering Clang warns about `if(ret = 0)` I was expecting to get a
warning for the same thing in the context of `assert()` too. I understand from
reading other bugs that `assert()` gets special treatment from `-Wparentheses`
to avoid warning on common idioms such as `assert(x && "failure message");`,
but I hope there's a way to still accept those idioms while warning about
relatively-obvious typos such as the above.

Fwiw, GCC gives the kind of warning I would expect here:

foo.c:7:12: warning: suggest parentheses around assignment used as truth value
[-Wparentheses]

Please consider making Clang produce a similar warning in this instance.

Thanks,
Manuel.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>