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:
Eric Fiselier
2016-09-07 01:56:07 +00:00
parent 01609afe24
commit b9231a2326
9 changed files with 113 additions and 14 deletions

View File

@@ -62,6 +62,10 @@ public:
friend void swap(Z& x, Z& y) {throw 6;}
};
struct ConstSwappable {
};
void swap(ConstSwappable const&, ConstSwappable const&) {}
int main()
{
{
@@ -112,6 +116,11 @@ int main()
assert(static_cast<bool>(opt2) == true);
assert(*opt2 == 1);
}
{
optional<const ConstSwappable> opt;
optional<const ConstSwappable> opt2;
opt.swap(opt2);
}
{
optional<X> opt1;
optional<X> opt2;