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.

llvm-svn: 280775
This commit is contained in:
Eric Fiselier
2016-09-07 01:56:07 +00:00
parent edd0a7023f
commit c1d527d3d8
9 changed files with 113 additions and 14 deletions

View File

@@ -74,6 +74,17 @@ public:
friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;}
};
class ConstMovable
{
int i_;
public:
ConstMovable(int i) : i_(i) {}
ConstMovable(const ConstMovable&& x) : i_(x.i_) {}
~ConstMovable() {i_ = 0;}
friend bool operator==(const ConstMovable& x, const ConstMovable& y) {return x.i_ == y.i_;}
};
int main()
{
{
@@ -86,6 +97,11 @@ int main()
optional<T> rhs(3);
test(rhs);
}
{
typedef const int T;
optional<T> rhs(3);
test(rhs);
}
{
typedef X T;
optional<T> rhs;
@@ -96,6 +112,11 @@ int main()
optional<T> rhs(X(3));
test(rhs);
}
{
typedef const ConstMovable T;
optional<T> rhs(ConstMovable(3));
test(rhs);
}
{
typedef Y T;
optional<T> rhs;