libcxx initial import

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@103490 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/language.support/support.exception/exception.terminate/nothing_to_do.pass.cpp b/test/language.support/support.exception/exception.terminate/nothing_to_do.pass.cpp
new file mode 100644
index 0000000..fa4d462
--- /dev/null
+++ b/test/language.support/support.exception/exception.terminate/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/test/language.support/support.exception/exception.terminate/set.terminate/set_terminate.pass.cpp b/test/language.support/support.exception/exception.terminate/set.terminate/set_terminate.pass.cpp
new file mode 100644
index 0000000..21de6f2
--- /dev/null
+++ b/test/language.support/support.exception/exception.terminate/set.terminate/set_terminate.pass.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+ 
+// test set_terminate
+
+#include <exception>
+#include <cstdlib>
+#include <cassert>
+
+void f1() {}
+void f2() {}
+
+int main()
+{
+    std::set_terminate(f1);
+    assert(std::set_terminate(f2) == f1);
+}
diff --git a/test/language.support/support.exception/exception.terminate/terminate.handler/terminate_handler.pass.cpp b/test/language.support/support.exception/exception.terminate/terminate.handler/terminate_handler.pass.cpp
new file mode 100644
index 0000000..0a3a457
--- /dev/null
+++ b/test/language.support/support.exception/exception.terminate/terminate.handler/terminate_handler.pass.cpp
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+ 
+// test terminate_handler
+
+#include <exception>
+
+void f() {}
+
+int main()
+{
+    std::terminate_handler p = f;
+}
diff --git a/test/language.support/support.exception/exception.terminate/terminate/terminate.pass.cpp b/test/language.support/support.exception/exception.terminate/terminate/terminate.pass.cpp
new file mode 100644
index 0000000..b34051d
--- /dev/null
+++ b/test/language.support/support.exception/exception.terminate/terminate/terminate.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+ 
+// test terminate
+
+#include <exception>
+#include <cstdlib>
+#include <cassert>
+
+void f1()
+{
+    std::exit(0);
+}
+
+int main()
+{
+    std::set_terminate(f1);
+    std::terminate();
+    assert(false);
+}
diff --git a/test/language.support/support.exception/exception.unexpected/bad.exception/bad_exception.pass.cpp b/test/language.support/support.exception/exception.unexpected/bad.exception/bad_exception.pass.cpp
new file mode 100644
index 0000000..9f32dac
--- /dev/null
+++ b/test/language.support/support.exception/exception.unexpected/bad.exception/bad_exception.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test bad_exception
+
+#include <exception>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+    static_assert((std::is_base_of<std::exception, std::bad_exception>::value),
+                 "std::is_base_of<std::exception, std::bad_exception>::value");
+    static_assert(std::is_polymorphic<std::bad_exception>::value,
+                 "std::is_polymorphic<std::bad_exception>::value");
+    std::bad_exception b;
+    std::bad_exception b2 = b;
+    b2 = b;
+    const char* w = b2.what();
+    assert(w);
+}
diff --git a/test/language.support/support.exception/exception.unexpected/nothing_to_do.pass.cpp b/test/language.support/support.exception/exception.unexpected/nothing_to_do.pass.cpp
new file mode 100644
index 0000000..fa4d462
--- /dev/null
+++ b/test/language.support/support.exception/exception.unexpected/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/test/language.support/support.exception/exception.unexpected/set.unexpected/set_unexpected.pass.cpp b/test/language.support/support.exception/exception.unexpected/set.unexpected/set_unexpected.pass.cpp
new file mode 100644
index 0000000..6f52ab7
--- /dev/null
+++ b/test/language.support/support.exception/exception.unexpected/set.unexpected/set_unexpected.pass.cpp
@@ -0,0 +1,22 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+ 
+// test set_unexpected
+
+#include <exception>
+#include <cassert>
+
+void f1() {}
+void f2() {}
+
+int main()
+{
+    assert(std::set_unexpected(f1) == std::terminate);
+    assert(std::set_unexpected(f2) == f1);
+}
diff --git a/test/language.support/support.exception/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp b/test/language.support/support.exception/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp
new file mode 100644
index 0000000..dbb5606
--- /dev/null
+++ b/test/language.support/support.exception/exception.unexpected/unexpected.handler/unexpected_handler.pass.cpp
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+ 
+// test unexpected_handler
+
+#include <exception>
+
+void f() {}
+
+int main()
+{
+    std::unexpected_handler p = f;
+}
diff --git a/test/language.support/support.exception/exception.unexpected/unexpected/unexpected.pass.cpp b/test/language.support/support.exception/exception.unexpected/unexpected/unexpected.pass.cpp
new file mode 100644
index 0000000..0f441e2
--- /dev/null
+++ b/test/language.support/support.exception/exception.unexpected/unexpected/unexpected.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+ 
+// test unexpected
+
+#include <exception>
+#include <cstdlib>
+#include <cassert>
+
+void f1()
+{
+    std::exit(0);
+}
+
+int main()
+{
+    std::set_unexpected(f1);
+    std::unexpected();
+    assert(false);
+}
diff --git a/test/language.support/support.exception/exception/exception.pass.cpp b/test/language.support/support.exception/exception/exception.pass.cpp
new file mode 100644
index 0000000..d3ad7e4
--- /dev/null
+++ b/test/language.support/support.exception/exception/exception.pass.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test exception
+
+#include <exception>
+#include <type_traits>
+#include <cassert>
+
+int main()
+{
+    static_assert(std::is_polymorphic<std::exception>::value,
+                 "std::is_polymorphic<std::exception>::value");
+    std::exception b;
+    std::exception b2 = b;
+    b2 = b;
+    const char* w = b2.what();
+    assert(w);
+}
diff --git a/test/language.support/support.exception/propagation/current_exception.pass.cpp b/test/language.support/support.exception/propagation/current_exception.pass.cpp
new file mode 100644
index 0000000..95ba458
--- /dev/null
+++ b/test/language.support/support.exception/propagation/current_exception.pass.cpp
@@ -0,0 +1,269 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <exception>
+
+// exception_ptr current_exception();
+
+#include <exception>
+#include <cassert>
+
+struct A
+{
+    static int constructed;
+
+    A() {++constructed;}
+    ~A() {--constructed;}
+    A(const A&)  {++constructed;}
+};
+
+int A::constructed = 0;
+
+int main()
+{
+    {
+        std::exception_ptr p = std::current_exception();
+        assert(p == nullptr);
+    }
+    {
+        try
+        {
+            assert(A::constructed == 0);
+            throw A();
+            assert(false);
+        }
+        catch (...)
+        {
+            assert(A::constructed == 1);
+        }
+        assert(A::constructed == 0);
+    }
+    assert(A::constructed == 0);
+    {
+        std::exception_ptr p2;
+        try
+        {
+            assert(A::constructed == 0);
+            throw A();
+            assert(false);
+        }
+        catch (...)
+        {
+            std::exception_ptr p = std::current_exception();
+            assert(A::constructed == 1);
+            assert(p != nullptr);
+            p2 = std::current_exception();
+            assert(A::constructed == 1);
+            assert(p == p2);
+        }
+        assert(A::constructed == 1);
+    }
+    assert(A::constructed == 0);
+    {
+        std::exception_ptr p2;
+        try
+        {
+            assert(A::constructed == 0);
+            throw A();
+            assert(false);
+        }
+        catch (A& a)
+        {
+            std::exception_ptr p = std::current_exception();
+            assert(A::constructed == 1);
+            assert(p != nullptr);
+            p2 = std::current_exception();
+            assert(A::constructed == 1);
+            assert(p == p2);
+        }
+        assert(A::constructed == 1);
+    }
+    assert(A::constructed == 0);
+    {
+        std::exception_ptr p2;
+        try
+        {
+            assert(A::constructed == 0);
+            throw A();
+            assert(false);
+        }
+        catch (A a)
+        {
+            std::exception_ptr p = std::current_exception();
+            assert(A::constructed == 2);
+            assert(p != nullptr);
+            p2 = std::current_exception();
+            assert(A::constructed == 2);
+            assert(p == p2);
+        }
+        assert(A::constructed == 1);
+    }
+    assert(A::constructed == 0);
+    {
+        try
+        {
+            assert(A::constructed == 0);
+            throw A();
+            assert(false);
+        }
+        catch (...)
+        {
+            assert(A::constructed == 1);
+            try
+            {
+                assert(A::constructed == 1);
+                throw;
+                assert(false);
+            }
+            catch (...)
+            {
+                assert(A::constructed == 1);
+            }
+            assert(A::constructed == 1);
+        }
+        assert(A::constructed == 0);
+    }
+    assert(A::constructed == 0);
+    {
+        try
+        {
+            assert(A::constructed == 0);
+            throw A();
+            assert(false);
+        }
+        catch (...)
+        {
+            assert(A::constructed == 1);
+            try
+            {
+                std::exception_ptr p = std::current_exception();
+                assert(A::constructed == 1);
+                assert(p != nullptr);
+                throw;
+                assert(false);
+            }
+            catch (...)
+            {
+                assert(A::constructed == 1);
+            }
+            assert(A::constructed == 1);
+        }
+        assert(A::constructed == 0);
+    }
+    assert(A::constructed == 0);
+    {
+        try
+        {
+            assert(A::constructed == 0);
+            throw A();
+            assert(false);
+        }
+        catch (...)
+        {
+            assert(A::constructed == 1);
+            try
+            {
+                assert(A::constructed == 1);
+                throw;
+                assert(false);
+            }
+            catch (...)
+            {
+                std::exception_ptr p = std::current_exception();
+                assert(A::constructed == 1);
+                assert(p != nullptr);
+            }
+            assert(A::constructed == 1);
+        }
+        assert(A::constructed == 0);
+    }
+    assert(A::constructed == 0);
+    {
+        try
+        {
+            assert(A::constructed == 0);
+            throw A();
+            assert(false);
+        }
+        catch (...)
+        {
+            assert(A::constructed == 1);
+            try
+            {
+                assert(A::constructed == 1);
+                throw;
+                assert(false);
+            }
+            catch (...)
+            {
+                assert(A::constructed == 1);
+            }
+            std::exception_ptr p = std::current_exception();
+            assert(A::constructed == 1);
+            assert(p != nullptr);
+        }
+        assert(A::constructed == 0);
+    }
+    assert(A::constructed == 0);
+    {
+        try
+        {
+            assert(A::constructed == 0);
+            throw A();
+            assert(false);
+        }
+        catch (...)
+        {
+            assert(A::constructed == 1);
+            try
+            {
+                assert(A::constructed == 1);
+                throw;
+                assert(false);
+            }
+            catch (...)
+            {
+                assert(A::constructed == 1);
+            }
+            assert(A::constructed == 1);
+        }
+        std::exception_ptr p = std::current_exception();
+        assert(A::constructed == 0);
+        assert(p == nullptr);
+    }
+    assert(A::constructed == 0);
+    {
+        std::exception_ptr p;
+        try
+        {
+            assert(A::constructed == 0);
+            throw A();
+            assert(false);
+        }
+        catch (...)
+        {
+            assert(A::constructed == 1);
+            try
+            {
+                assert(A::constructed == 1);
+                throw;
+                assert(false);
+            }
+            catch (...)
+            {
+                p = std::current_exception();
+                assert(A::constructed == 1);
+            }
+            assert(A::constructed == 1);
+        }
+        assert(A::constructed == 1);
+        assert(p != nullptr);
+    }
+    assert(A::constructed == 0);
+}
diff --git a/test/language.support/support.exception/propagation/exception_ptr.pass.cpp b/test/language.support/support.exception/propagation/exception_ptr.pass.cpp
new file mode 100644
index 0000000..6c01768
--- /dev/null
+++ b/test/language.support/support.exception/propagation/exception_ptr.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <exception>
+
+// typedef unspecified exception_ptr;
+
+// exception_ptr shall satisfy the requirements of NullablePointer.
+
+#include <exception>
+#include <cassert>
+
+int main()
+{
+    std::exception_ptr p;
+    assert(p == nullptr);
+    std::exception_ptr p2 = p;
+    assert(nullptr == p);
+    assert(!p);
+    assert(p2 == p);
+    p2 = p;
+    assert(p2 == p);
+    assert(p2 == nullptr);
+    std::exception_ptr p3 = nullptr;
+    assert(p3 == nullptr);
+    p3 = nullptr;
+    assert(p3 == nullptr);
+}
diff --git a/test/language.support/support.exception/propagation/make_exception_ptr.pass.cpp b/test/language.support/support.exception/propagation/make_exception_ptr.pass.cpp
new file mode 100644
index 0000000..794199f
--- /dev/null
+++ b/test/language.support/support.exception/propagation/make_exception_ptr.pass.cpp
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <exception>
+
+// template<class E> exception_ptr make_exception_ptr(E e);
+
+#include <exception>
+#include <cassert>
+
+struct A
+{
+    static int constructed;
+    int data_;
+
+    A(int data = 0) : data_(data) {++constructed;}
+    ~A() {--constructed;}
+    A(const A& a) : data_(a.data_) {++constructed;}
+};
+
+int A::constructed = 0;
+
+int main()
+{
+    {
+        std::exception_ptr p = std::make_exception_ptr(A(5));
+        try
+        {
+            std::rethrow_exception(p);
+            assert(false);
+        }
+        catch (const A& a)
+        {
+            assert(A::constructed == 1);
+            assert(p != nullptr);
+            p = nullptr;
+            assert(p == nullptr);
+            assert(a.data_ == 5);
+            assert(A::constructed == 1);
+        }
+        assert(A::constructed == 0);
+    }
+}
diff --git a/test/language.support/support.exception/propagation/rethrow_exception.pass.cpp b/test/language.support/support.exception/propagation/rethrow_exception.pass.cpp
new file mode 100644
index 0000000..6cb19f7
--- /dev/null
+++ b/test/language.support/support.exception/propagation/rethrow_exception.pass.cpp
@@ -0,0 +1,57 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <exception>
+
+// void rethrow_exception [[noreturn]] (exception_ptr p);
+
+#include <exception>
+#include <cassert>
+
+struct A
+{
+    static int constructed;
+    int data_;
+
+    A(int data = 0) : data_(data) {++constructed;}
+    ~A() {--constructed;}
+    A(const A& a) : data_(a.data_) {++constructed;}
+};
+
+int A::constructed = 0;
+
+int main()
+{
+    {
+        std::exception_ptr p;
+        try
+        {
+            throw A(3);
+        }
+        catch (...)
+        {
+            p = std::current_exception();
+        }
+        try
+        {
+            std::rethrow_exception(p);
+            assert(false);
+        }
+        catch (const A& a)
+        {
+            assert(A::constructed == 1);
+            assert(p != nullptr);
+            p = nullptr;
+            assert(p == nullptr);
+            assert(a.data_ == 3);
+            assert(A::constructed == 1);
+        }
+        assert(A::constructed == 0);
+    }
+}
diff --git a/test/language.support/support.exception/uncaught/uncaught_exception.pass.cpp b/test/language.support/support.exception/uncaught/uncaught_exception.pass.cpp
new file mode 100644
index 0000000..33ee877
--- /dev/null
+++ b/test/language.support/support.exception/uncaught/uncaught_exception.pass.cpp
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// test uncaught_exception
+
+#include <exception>
+#include <cassert>
+
+struct A
+{
+    ~A()
+    {
+        assert(std::uncaught_exception());
+    }
+};
+
+int main()
+{
+    try
+    {
+        A a;
+        assert(!std::uncaught_exception());
+        throw 1;
+    }
+    catch (...)
+    {
+        assert(!std::uncaught_exception());
+    }
+    assert(!std::uncaught_exception());
+}
diff --git a/test/language.support/support.exception/version.pass.cpp b/test/language.support/support.exception/version.pass.cpp
new file mode 100644
index 0000000..db3013e
--- /dev/null
+++ b/test/language.support/support.exception/version.pass.cpp
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <exception>
+
+#include <exception>
+
+#ifndef _LIBCPP_VERSION
+#error _LIBCPP_VERSION not defined
+#endif
+
+int main()
+{
+}