diff options
Diffstat (limited to 'libcxx/test/support/test.support')
5 files changed, 173 insertions, 0 deletions
diff --git a/libcxx/test/support/test.support/test_convertible_header.pass.cpp b/libcxx/test/support/test.support/test_convertible_header.pass.cpp new file mode 100644 index 00000000000..a56b84b4739 --- /dev/null +++ b/libcxx/test/support/test.support/test_convertible_header.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// "support/test_convertible.hpp" + +#include "test_convertible.hpp" + +struct ImplicitDefault { + ImplicitDefault() {} +}; +static_assert(test_convertible<ImplicitDefault>(), "Must be convertible"); + +struct ExplicitDefault { + explicit ExplicitDefault() {} +}; +static_assert(!test_convertible<ExplicitDefault>(), "Must not be convertible"); + +struct ImplicitInt { + ImplicitInt(int) {} +}; +static_assert(test_convertible<ImplicitInt, int>(), "Must be convertible"); + +struct ExplicitInt { + explicit ExplicitInt(int) {} +}; +static_assert(!test_convertible<ExplicitInt, int>(), "Must not be convertible"); + +struct ImplicitCopy { + ImplicitCopy(ImplicitCopy const&) {} +}; +static_assert(test_convertible<ImplicitCopy, ImplicitCopy>(), "Must be convertible"); + +struct ExplicitCopy { + explicit ExplicitCopy(ExplicitCopy const&) {} +}; +static_assert(!test_convertible<ExplicitCopy, ExplicitCopy>(), "Must not be convertible"); + +struct ImplicitMove { + ImplicitMove(ImplicitMove&&) {} +}; +static_assert(test_convertible<ImplicitMove, ImplicitMove>(), "Must be convertible"); + +struct ExplicitMove { + explicit ExplicitMove(ExplicitMove&&) {} +}; +static_assert(!test_convertible<ExplicitMove, ExplicitMove>(), "Must not be convertible"); + +struct ImplicitArgs { + ImplicitArgs(int, int, int) {} +}; +static_assert(test_convertible<ImplicitArgs, int, int, int>(), "Must be convertible"); + +struct ExplicitArgs { + explicit ExplicitArgs(int, int, int) {} +}; +static_assert(!test_convertible<ExplicitArgs, int, int, int>(), "Must not be convertible"); + +int main() { + // Nothing to do +} diff --git a/libcxx/test/support/test.support/test_macros_header_exceptions.fail.cpp b/libcxx/test/support/test.support/test_macros_header_exceptions.fail.cpp new file mode 100644 index 00000000000..ade2cd98fe0 --- /dev/null +++ b/libcxx/test/support/test.support/test_macros_header_exceptions.fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// "support/test_macros.hpp" + +// #define TEST_HAS_NO_EXCEPTIONS + +#include "test_macros.h" + +int main() { +#if defined(TEST_HAS_NO_EXCEPTIONS) + try { ((void)0); } catch (...) {} // expected-error {{exceptions disabled}} +#else + try { ((void)0); } catch (...) {} +#error exceptions enabled +// expected-error@-1 {{exceptions enabled}} +#endif +} diff --git a/libcxx/test/support/test.support/test_macros_header_exceptions.pass.cpp b/libcxx/test/support/test.support/test_macros_header_exceptions.pass.cpp new file mode 100644 index 00000000000..589e148a003 --- /dev/null +++ b/libcxx/test/support/test.support/test_macros_header_exceptions.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: libcpp-no-exceptions + +// "support/test_macros.hpp" + +// #define TEST_HAS_NO_EXCEPTIONS + +#include "test_macros.h" + +#if defined(TEST_HAS_NO_EXCEPTIONS) +#error macro defined unexpectedly +#endif + +int main() { + try { ((void)0); } catch (...) {} +} diff --git a/libcxx/test/support/test.support/test_macros_header_rtti.fail.cpp b/libcxx/test/support/test.support/test_macros_header_rtti.fail.cpp new file mode 100644 index 00000000000..851a6c60141 --- /dev/null +++ b/libcxx/test/support/test.support/test_macros_header_rtti.fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// "support/test_macros.hpp" + +// #define TEST_HAS_NO_RTTI + +#include "test_macros.h" + +struct A { virtual ~A() {} }; +struct B : A {}; + +int main() { +#if defined(TEST_HAS_NO_RTTI) + A* ptr = new B; + (void)dynamic_cast<B*>(ptr); // expected-error{{cannot use dynamic_cast}} +#else + A* ptr = new B; + (void)dynamic_cast<B*>(ptr); +#error RTTI enabled +// expected-error@-1{{RTTI enabled}} +#endif +} diff --git a/libcxx/test/support/test.support/test_macros_header_rtti.pass.cpp b/libcxx/test/support/test.support/test_macros_header_rtti.pass.cpp new file mode 100644 index 00000000000..d189a0efc2f --- /dev/null +++ b/libcxx/test/support/test.support/test_macros_header_rtti.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: libcpp-no-rtti + +// "support/test_macros.hpp" + +// #define TEST_HAS_NO_RTTI + +#include "test_macros.h" + +#if defined(TEST_HAS_NO_RTTI) +#error Macro defined unexpectedly +#endif + +struct A { virtual ~A() {} }; +struct B : A {}; + +int main() { + A* ptr = new B; + (void)dynamic_cast<B*>(ptr); +} |