[LLVMbugs] [Bug 16538] New: map<K, V>::find(K()) is ambiguous if K has a template constructor

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jul 3 20:35:42 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=16538

            Bug ID: 16538
           Summary: map<K,V>::find(K()) is ambiguous if K has a template
                    constructor
           Product: libc++
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: All Bugs
          Assignee: hhinnant at apple.com
          Reporter: likan_999.student at sina.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Note: this is not the same issue as http://llvm.org/bugs/show_bug.cgi?id=12027.
Note: g++ 4.8.1 can compile it successfully.
Note: the libc++ is at trunk version.


[hidden ~]$ cat b.cpp
#include <map>

struct Key {
  template <typename T> Key(const T&) {}
  bool operator< (const Key&) const { return false; }
};
auto it = std::map<Key, int>().find(Key(0));

[hidden ~]$ g++ -std=c++11 -c b.cpp
[hidden ~]$ clang++ -std=c++11 -stdlib=libc++ -c b.cpp
In file included from b.cpp:1:
In file included from /usr/include/c++/v1/map:371:
/usr/include/c++/v1/__tree:2020:26: error: call to object of type
'value_compare' (aka 'std::__1::__map_value_compare<Key, int,
std::__1::less<Key>, true>') is ambiguous
    if (__p != end() && !value_comp()(__v, *__p))
                         ^~~~~~~~~~~~
/usr/include/c++/v1/map:1006:68: note: in instantiation of function template
specialization 'std::__1::__tree<std::__1::map<Key, int, std::__1::less<Key>,
      std::__1::allocator<std::__1::pair<const Key, int> > >::__value_type,
std::__1::__map_value_compare<Key, int, std::__1::less<Key>, true>,
      std::__1::allocator<std::__1::map<Key, int, std::__1::less<Key>,
std::__1::allocator<std::__1::pair<const Key, int> > >::__value_type>
>::find<Key>' requested here
    iterator find(const key_type& __k)             {return __tree_.find(__k);}
                                                                   ^
b.cpp:7:32: note: in instantiation of member function 'std::__1::map<Key, int,
std::__1::less<Key>, std::__1::allocator<std::__1::pair<const Key, int> >
>::find'
      requested here
auto it = std::map<Key, int>().find(Key(0));
                               ^
/usr/include/c++/v1/map:424:10: note: candidate function
    bool operator()(const _Key& __x, const _CP& __y) const
         ^
/usr/include/c++/v1/map:430:10: note: candidate function
    bool operator()(const _Key& __x, const _Key& __y) const
         ^
In file included from b.cpp:1:
In file included from /usr/include/c++/v1/map:371:
/usr/include/c++/v1/__tree:2093:14: error: call to object of type
'value_compare' (aka 'std::__1::__map_value_compare<Key, int,
std::__1::less<Key>, true>') is ambiguous
        if (!value_comp()(__root->__value_, __v))
             ^~~~~~~~~~~~
/usr/include/c++/v1/__tree:2019:20: note: in instantiation of function template
specialization 'std::__1::__tree<std::__1::map<Key, int, std::__1::less<Key>,
      std::__1::allocator<std::__1::pair<const Key, int> > >::__value_type,
std::__1::__map_value_compare<Key, int, std::__1::less<Key>, true>,
      std::__1::allocator<std::__1::map<Key, int, std::__1::less<Key>,
std::__1::allocator<std::__1::pair<const Key, int> > >::__value_type>
>::__lower_bound<Key>'
      requested here
    iterator __p = __lower_bound(__v, __root(), __end_node());
                   ^
/usr/include/c++/v1/map:1006:68: note: in instantiation of function template
specialization 'std::__1::__tree<std::__1::map<Key, int, std::__1::less<Key>,
      std::__1::allocator<std::__1::pair<const Key, int> > >::__value_type,
std::__1::__map_value_compare<Key, int, std::__1::less<Key>, true>,
      std::__1::allocator<std::__1::map<Key, int, std::__1::less<Key>,
std::__1::allocator<std::__1::pair<const Key, int> > >::__value_type>
>::find<Key>' requested here
    iterator find(const key_type& __k)             {return __tree_.find(__k);}
                                                                   ^
b.cpp:7:32: note: in instantiation of member function 'std::__1::map<Key, int,
std::__1::less<Key>, std::__1::allocator<std::__1::pair<const Key, int> >
>::find'
      requested here
auto it = std::map<Key, int>().find(Key(0));
                               ^
/usr/include/c++/v1/map:412:10: note: candidate function
    bool operator()(const _CP& __x, const _Key& __y) const
         ^
/usr/include/c++/v1/map:430:10: note: candidate function
    bool operator()(const _Key& __x, const _Key& __y) const
         ^
2 errors generated.

-- 
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/20130704/7caf6a81/attachment.html>


More information about the llvm-bugs mailing list