Is the core of std :: map default?

The following code compiles in g ++ (various versions), but does not work on clang ++ - 3.4 with libC ++ on my system:

#include <map>
#include <string>

std::map<std::string, std::string> f() {
    return {};
}

int main() {
    auto m = f();
}

clang notes the following problem:

x.cpp:6:12: error: chosen constructor is explicit in copy-initialization
    return {};
           ^~
/usr/local/Cellar/llvm34/3.4.2/lib/llvm-3.4/bin/../include/c++/v1/map:838:14: note: constructor declared here
    explicit map(const key_compare& __comp = key_compare())
             ^

In fact, the include file declares the constructor as explicit. But it is not marked as such in my standard C ++ 11 project.Is this a bug in clang ++ / libC ++? I could not find the appropriate error report.

+6
source share
1 answer

Prior to C ++ 14, there is no empty constructor. The default construct for is std::map<Key, Value, Compare, Allocator>marked with explicittwo default options, while C ++ 14:

explicit map( const Compare& comp = Compare(), 
              const Allocator& alloc = Allocator() );

++ 14 explicit, explicit ( Compare):

map() : map( Compare() ) {}
explicit map( const Compare& comp, 
              const Allocator& alloc = Allocator() );

, ++ 14.

: http://en.cppreference.com/w/cpp/container/map/map

+9

All Articles