Last active
August 29, 2015 14:23
-
-
Save maxtruxa/97ba44d24da534dfbad6 to your computer and use it in GitHub Desktop.
VC++ bug: std::unique_ptr with std::is_same<element_type, pointer>::value == true
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <memory> | |
int main() { | |
struct my_type { | |
void poke() { std::cout << "poke\n"; } | |
}; | |
typedef my_type* my_type_ptr; | |
struct my_deleter { | |
typedef my_type_ptr pointer; | |
void operator()(my_type_ptr p) { delete p; } | |
}; | |
typedef std::unique_ptr<my_type_ptr, my_deleter> my_unique_ptr; | |
my_unique_ptr x(new my_type); | |
x->poke(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
VS2013: The culprit seems to be
std::unique_ptr::operator->()
:The C++ standard does not mandate this unnecessary complex implementation. Quoting the latest working draft (N4296)
§20.8.1.2.4 unique_ptr observers
:VC++'s
std::unique_ptr::get()
looks like this:GCC and LLVM both use the obvious (and actually working) implementation of
std::unique_ptr::operator->()
, that would look like this in VC++: