<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 - False negative analyse c++ code in asserts"
   href="https://bugs.llvm.org/show_bug.cgi?id=46238">46238</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>False negative analyse c++ code in asserts
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </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>spider.ch@gmail.com
          </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>Hello.
I found an issue with warnings and asserts.
Let's say we have code:


    #include <cassert>

    enum class State
    {
        A = 0,
        B,
        C,
        D,
        E,
        F
    };

    void ProcessState(State s)
    {
        assert(s > State::A || s < State::E); // < No warning
        (__builtin_expect(!(s > State::A || s < State::E), 0) ?
__assert_rtn(__func__, "main.cpp", 15, "s > State::A || s < State::E") :
(void)0); // < main.cpp:16:38: warning: overlapping comparisons always evaluate
to true [-Wtautological-overlap-compare]
        if (s > State::A || s < State::E) // < main.cpp:17:22: warning:
overlapping comparisons always evaluate to true
[-Wtautological-overlap-compare]
            void(0);
    }

    int main(int, char**)
    {
        ProcessState(State::B);
        return 0;
    }

And compile code with:
    clang++ -std=c++17 -g -O1 -Wtautological-compare main.cpp -o test

There will be no warning on line 15, but there is a mistake. If we move code
from assert to if or change assert with preprocessed code (as in line 16) then
a warning appears.

This behavior was seen in clang 5.0(Maybe and earlier, but I didn't check) and
later.</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>