mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-25 04:56:13 +08:00
Fix PR30260 - optional<const T> not working.
This patch fixes PR30260 by using a (void*) cast on the placement argument to placement new to casts away the const. See also http://llvm.org/PR30260. As a drive by change this patch also changes the header guard for <experimental/optional> to _LIBCPP_EXPERIMENTAL_OPTIONAL from _LIBCPP_OPTIONAL. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@280775 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -19,6 +19,14 @@
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct AllowConstAssign {
|
||||
AllowConstAssign() = default;
|
||||
AllowConstAssign(AllowConstAssign const&) {}
|
||||
AllowConstAssign const& operator=(AllowConstAssign const&) const {
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
@@ -52,6 +60,11 @@ int main()
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == i);
|
||||
}
|
||||
{
|
||||
optional<const AllowConstAssign> opt;
|
||||
const AllowConstAssign other;
|
||||
opt = other;
|
||||
}
|
||||
{
|
||||
optional<std::unique_ptr<int>> opt;
|
||||
opt = std::unique_ptr<int>(new int(3));
|
||||
|
||||
Reference in New Issue
Block a user