<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 when pop_front from std::list<unique_ptr<T>> in C++11"
   href="http://llvm.org/bugs/show_bug.cgi?id=19637">19637</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>False-positive when pop_front from std::list<unique_ptr<T>>  in C++11
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.4
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </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>renauxthierry+llvmBugzilla@gmail.com
          </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>The following C++11 code is a minimal example of what I believe triggers a
false positive in the clang static analyzer:


*** begin code ***

#include <iostream>
#include <list>
#include <memory>

class ElementType {};

int main(int argc, const char * argv[]) {
    std::list<std::unique_ptr<ElementType>> theList(5);

    theList.pop_front();

    for (const auto &element: theList) { // (*)
        std::cout << "This should be fine." << std::endl;
    }

    return 0;
}

*** end code ***


On the line marked by an asterisk (*), the clang analyzer claims
".../main.cpp:21:29: Use of memory after it is freed (within a call to
'begin')"

As far as I see, this code is harmless. My guess is that the analyzer misses
the point that std::list<T>::pop_front() not only calls its elements'
destructor, but that it also moves the location of std::list<T>::begin().
Replacing the call to pop_front by pop_back makes the analyzer warning
disappear, and even replacing it by erase(theList.begin()) makes it come out
warning-free.

For reference: These results come from XCode 5.1.1 (5B1008) on Mac OS X 10.9.2,
clang --version "Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM
3.4svn)", "Target: x86_64-apple-darwin13.1.0", "Thread model: posix"</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>