<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 positive with containers & loop initialized value, container excluding assumptions with empty() with size()"
   href="http://llvm.org/bugs/show_bug.cgi?id=17489">17489</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>False positive with containers & loop initialized value, container excluding assumptions with empty() with size()
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>kremenek@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>artur@ebasoft.com.pl
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>For this code below analyzer assumes !empty() and size()==0 as a possible case
clang version 3.4 (191810)


#include <iostream>
#include <vector>

struct foo_t{ int value; void prt(){ std::cout << "Hello, world!"<< value <<
std::endl;}};
using foo_list_t =std::vector<foo_t>;

void func( foo_list_t & foo_list )
  {
  if( !foo_list.empty() )
    {
    foo_t * first_foo = nullptr;
    for( size_t i=0; i<foo_list.size(); ++i)
      {
      if( i == 0 )
        first_foo = &foo_list[i];
        std::cout << ".";
      }
    first_foo->prt();
    }
  }
int main(int argc, char **argv)
{
    foo_list_t foo_list{ {0},{1},{2}};
    func(foo_list);
    return 0;
}

-----------------------------------------------
9      if( !foo_list.empty() )
2
←Taking true branch→
10        {
11        foo_t * first_foo = nullptr;
3
←'first_foo' initialized to a null pointer value

12        for( size_t i=0; i<foo_list.size(); ++i)
4
←Loop condition is false. Execution continues on line 18

13          {
14          if( i == 0 )
15            first_foo = &foo_list[i];
16            std::cout << ".";
17          }
18        first_foo->prt();
5
←Called C++ object pointer is null
19        }</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>