<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 - undefined symbol when linking code that uses vector header"
   href="https://bugs.llvm.org/show_bug.cgi?id=33371">33371</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>undefined symbol when linking code that uses vector header
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

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

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </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>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>michaeljclark@mac.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18601" name="attach_18601" title="inline exceptions in __vector_base_common">attachment 18601</a> <a href="attachment.cgi?id=18601&action=edit" title="inline exceptions in __vector_base_common">[details]</a></span>
inline exceptions in __vector_base_common

The following link error occurs when linking code that uses std::vector

Undefined symbols for architecture x86_64:
  "std::__1::__vector_base_common<true>::__throw_length_error() const",
referenced from:
  <snip>

It appears that the header violates ODR? It is unusual to have out of line
function bodies declared in a template header. I'm not sure of the rationale of
having these out of line, and if so they should be declared in src/vector.cpp.
The attached patch solves the problem.

--- a/include/vector
+++ b/include/vector
@@ -290,24 +290,16 @@ class __vector_base_common
 {
 protected:
     _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
-    _LIBCPP_NORETURN void __throw_length_error() const;
-    _LIBCPP_NORETURN void __throw_out_of_range() const;
+    _LIBCPP_NORETURN _LIBCPP_ALWAYS_INLINE void __throw_length_error() const
+    {
+        _VSTD::__throw_length_error("vector");
+    }
+    _LIBCPP_NORETURN _LIBCPP_ALWAYS_INLINE void __throw_out_of_range() const
+    {
+        _VSTD::__throw_out_of_range("vector");
+    }
 };

-template <bool __b>
-void
-__vector_base_common<__b>::__throw_length_error() const
-{
-    _VSTD::__throw_length_error("vector");
-}
-
-template <bool __b>
-void
-__vector_base_common<__b>::__throw_out_of_range() const
-{
-    _VSTD::__throw_out_of_range("vector");
-}
-
 #ifdef _LIBCPP_MSVC
 #pragma warning( push )
 #pragma warning( disable: 4231 )</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>