<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 for Logic Error on std::set_difference when using std::insert(std::set<>, std::set<>::iterator)"
   href="http://llvm.org/bugs/show_bug.cgi?id=16704">16704</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>False positive for Logic Error on std::set_difference when using std::insert(std::set<>, std::set<>::iterator)
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </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>clang-bugzilla@cabbits.net
          </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>Seen on XCode 4.6,
Apple clang version 4.0 (tags/Apple/clang-421.10.60) (based on LLVM 3.1svn)

The following code compiled in obj-c++ in a new XCode project OSX C++ Library
template (but seen using other templates as well):

  std::set<int> set1 = {1, 2, 5, 7, 9};
  std::set<int> set2 = {2, 3, 5, 8, 10};
  std::set<int> set3;

  std::set_difference(set1.begin(), set1.end(),
                      set2.begin(), set2.end(),
                      std::inserter(set3, set3.begin()));

Produces a logic error:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/__tree:253:30:
Access to field '__is_black_' results in a dereference of a null pointer
(loaded from field '__parent_')

Trace:

/Users/nall/Desktop/TestLibrary/DemoClass.mm:21:3: Calling 'set_difference'
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/algorithm:5209:1:
Entered call from 'TestSet'
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/algorithm:5214:12:
Calling 'set_difference'
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/algorithm:5193:1:
Entered call from 'set_difference'
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/algorithm:5204:12:
Calling '__set_difference'
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/algorithm:5168:1:
Entered call from 'set_difference'
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/algorithm:5172:5:
Looping back to the head of the loop
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/algorithm:5172:5:
Looping back to the head of the loop
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/algorithm:5172:5:
Looping back to the head of the loop
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/algorithm:5178:13:
Calling 'operator='
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/iterator:701:5:
Entered call from '__set_difference'
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/iterator:702:17:
Calling 'insert'
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/set:533:5:
Entered call from 'operator='
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/set:535:17:
Calling '__insert_unique'
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/__tree:1865:1:
Entered call from 'insert'
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/__tree:1874:9:
Calling '__insert_node_at'
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/__tree:1690:1:
Entered call from '__insert_unique'
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/__tree:1701:5:
Calling '__tree_balance_after_insert'
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/__tree:249:1:
Entered call from '__insert_node_at'
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/__tree:253:30:
Access to field '__is_black_' results in a dereference of a null pointer
(loaded from field '__parent_')

This does not occur when a std::vector<> or other containers are used with
std::inserter().  This appears to be a spurious warning, but I am not sure of
the proper resolution.</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>