https://bugs.llvm.org/show_bug.cgi?id=33371

            Bug ID: 33371
           Summary: undefined symbol when linking code that uses vector
                    header
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]

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:
  <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 )

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to