[cfe-dev] Issue with map and unordered_map: call to deleted constructor of 'std::pair<const int, int>'

David Blaikie dblaikie at gmail.com
Sat Sep 17 13:25:24 PDT 2011


On Sat, Sep 17, 2011 at 1:12 PM, Matthieu Monrocq <
matthieu.monrocq at gmail.com> wrote:

> I just updated (and compiled) clang this afternoon, and a piece of code I
> had written simply does not work any longer.
>
> It boils down to the following code:
>
> struct Foo {};
>
> void foo(unsigned u) {
>   std::unordered_map<unsigned, Foo> map;
>   map.insert(std::make_pair(u, Foo())); // the offending line, also occurs
> with a std::map
> }
>
> And I got a huge backtrace... eurk.
>
> I managed to reduce the test case to:
>
> #include <utility> // 1
>
> template <typename V>
> struct Node {
>   V value;
>
>   template <typename... Args>
>   Node(Args&&... args): value(std::forward<Args>(args)...) {} // 8
> };
>
> void foo(std::pair<int const, int> const& p) {
>   Node<std::pair<int const, int>> node(p); // 12
> }
>
> Where <utility> is picked up from the MinGW implementation of gcc 4.5.2. I
> get this error:
>
> unordered_map.cpp:8:25: error: call to deleted constructor of
> 'std::pair<const int, int>'
>   Node(Args&&... args): value(std::forward<Args>(args)...) {}
>                         ^     ~~~~~~~~~~~~~~~~~~~~~~~~
> unordered_map.cpp:12:35: note: in instantiation of function template
> specialization 'Node<std::pair<const int, int> >::Node<const
> std::pair<const int, int> &>' requested here
>   Node<std::pair<int const, int>> node(p);
>                                   ^
> /mingw/lib/gcc/mingw32/4.5.2/include/c++\bits/stl_pair.h:71:12: note:
> function has been explicitly marked deleted here
>     struct pair
>            ^
> 1 error generated.
>
> The full invocation (with the version of clang) and the preprocessed file
> can be found in attachment, for those interested.
>
> I was wondering if this is a bug in the gcc 4.5.2 standard library or a bug
> in clang... and I'd really appreciate a work-around if anyone has one, since
> I'm pretty much stuck at this point.


As a baseline, this code compiles successfully when using libc++ (compile
with -stdlib=libc++, though you'll of course need to install libc++) & I
seem to have a repro of your errors with libstdc++ so I'm playing around
with that now.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110917/69118246/attachment.html>


More information about the cfe-dev mailing list