[llvm-bugs] [Bug 33371] New: undefined symbol when linking code that uses vector header

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jun 8 17:33:38 PDT 2017


            Bug ID: 33371
           Summary: undefined symbol when linking code that uses vector
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: michaeljclark at mac.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

Created attachment 18601
  --> https://bugs.llvm.org/attachment.cgi?id=18601&action=edit
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:

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
     _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>
-__vector_base_common<__b>::__throw_length_error() const
-    _VSTD::__throw_length_error("vector");
-template <bool __b>
-__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 )

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170609/563407d4/attachment-0001.html>

More information about the llvm-bugs mailing list