<html>
    <head>
      <base href="https://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 --- - std::basic_string requires Allocator to have a default constructor"
   href="https://llvm.org/bugs/show_bug.cgi?id=24933">24933</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>std::basic_string requires Allocator to have a default constructor
          </td>
        </tr>

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

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

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

        <tr>
          <th>Reporter</th>
          <td>jhall1024+llvmbugs@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Instantiating std::basic_string<char, std::char_traits<char>,
MyAllocator<char>> fails if MyAllocator doesn't have a default constructor.
Allocators are not supposed to require a default constructor, and with stateful
allocators in C++11 a default constructor doesn't make sense.

Tried with Xcode 5.1.1 (Apple clang 3.6) and a custom OSX clang 3.6 build. I
assume this means libc++ 3.6; I don't know how to check the libc++ version.

test.cpp:
#include <cstdlib>
#include <string>

template <typename T>
class MyAllocator {
public:
    typedef T value_type;

    // Uncomment to compile successfully. Should not be needed.
    // MyAllocator() {}

    template <typename U>
    MyAllocator(const MyAllocator<U>&& other) {}

    T* allocate(size_t n) {
        return static_cast<T*>(malloc(n * sizeof(T)));
    }

    void deallocate(T* p, size_t /*n*/) {
        free(p);
    }
};

int main(int /*argc*/, char* /*argv*/[]) {
    std::basic_string<char, std::char_traits<char>, MyAllocator<char>>
str("Hello, world!");
    return 0;
}

$ clang --version
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.5.0
Thread model: posix

$ clang -Wall -std=c++11 -c test.cpp -o test.o
In file included from test.cpp:2:
In file included from
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:439:
In file included from
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:628:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2136:31:
error: constructor for
'std::__1::__libcpp_compressed_pair_imp<std::__1::basic_string<char,
std::__1::char_traits<char>, MyAllocator<char> >::__rep, MyAllocator<char>, 2>'
must explicitly initialize the base class 'MyAllocator<char>' which does not
have a default constructor
    _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
                              ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2315:31:
note: in instantiation of member function
'std::__1::__libcpp_compressed_pair_imp<std::__1::basic_string<char,
std::__1::char_traits<char>, MyAllocator<char> >::__rep, MyAllocator<char>,
2>::__libcpp_compressed_pair_imp' requested here
    _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
                              ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:1387:31:
note: in instantiation of member function
'std::__1::__compressed_pair<std::__1::basic_string<char,
std::__1::char_traits<char>, MyAllocator<char> >::__rep, MyAllocator<char>
<span class="quote">>::__compressed_pair' requested here</span >
    _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
                              ^
test.cpp:25:72: note: in instantiation of member function
'std::__1::basic_string<char, std::__1::char_traits<char>, MyAllocator<char>
<span class="quote">>::basic_string' requested here</span >
    std::basic_string<char, std::char_traits<char>, MyAllocator<char>>
str("Hello, world!");
                                                                       ^
test.cpp:5:7: note: 'MyAllocator<char>' declared here
class MyAllocator {
      ^
1 error generated.</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>