http://llvm.org/bugs/show_bug.cgi?id=17489

            Bug ID: 17489
           Summary: False positive with containers & loop initialized
                    value, container excluding assumptions with empty()
                    with size()
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

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        }

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to