1

A question I recently tried to answer seemed to be an error in vs2012's c++11 support.

Specifically, It failed to compile std::map with a non copy-constructible value_type, despite only std::move being used to insert into the map. Either the wrong insert overload is chosen, or the compiler doesn't consider the alternative.

Basically, I wan't to know if the following code:

#include <iostream>
#include <memory>
#include <utility>
#include <type_traits>

class Foo {
};

using namespace std;

int main() {
    cout << is_constructible<pair<const int,unique_ptr<Foo> >, pair<const int,unique_ptr<Foo> >& >::value << '\n';
    cout << is_constructible<pair<const int,unique_ptr<Foo> >, pair<const int,unique_ptr<Foo> >&& >::value << '\n';
}

gives the output 01.

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
user3125280
  • 2,779
  • 1
  • 14
  • 23

1 Answers1

1

Visual Studio outputs(see it live):

1
1

Which is clearly wrong and both gcc and clang give the expected results. This bug and the original issue you are seeing may be related to these two accepted bug reports. The incorrect results from is_constructible may actually be unrelated to the original bug:

Community
  • 1
  • 1
Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
  • sorry, a little clarification please: the original bug, as in the other answer? – user3125280 Jan 12 '14 at 04:14
  • it appears the compiler thinks it is copy constructible, and only discovers latter it was wrong, when it generates the copy constructor. i'll add a few more cases, if that's ok EDIT i see you were one step ahead, thanks. still, what do you mean by "original issue"? – user3125280 Jan 12 '14 at 04:15
  • @user3125280 I was referring to [this](http://stackoverflow.com/questions/21056872/c-stdunique-ptr-wont-compile-in-map) as the original issue. – Shafik Yaghmour Jan 12 '14 at 04:18
  • thought so - for reference, my answer to the other question does work, (i didn't know there was a vc online before) so there appears to be a relation - vc wrongly considers the impossible insert overload, because it assumes copy ctor exists. other compilers work correctly and don't consider that overload EDIT: actually, it works without my answer too.. so OP must of been doing something weird.. thanks anyway – user3125280 Jan 12 '14 at 04:27
  • @user3125280 it is a neat tool, I have what I think is a complete list [here](http://stackoverflow.com/a/14652386/1708801) and I try to keep it up to date. – Shafik Yaghmour Jan 12 '14 at 04:36