From 88d38802e27244bb6fc074d4e981d3df42be61c1 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Wed, 22 Jun 2016 05:29:15 +0000 Subject: Add tests for RTTI/exceptions test macros. llvm-svn: 273382 --- .../test.support/test_convertible_header.pass.cpp | 68 ++++++++++++++++++++++ .../test_macros_header_exceptions.fail.cpp | 24 ++++++++ .../test_macros_header_exceptions.pass.cpp | 24 ++++++++ .../test.support/test_macros_header_rtti.fail.cpp | 29 +++++++++ .../test.support/test_macros_header_rtti.pass.cpp | 28 +++++++++ .../test/support/test_convertible_header.pass.cpp | 68 ---------------------- 6 files changed, 173 insertions(+), 68 deletions(-) create mode 100644 libcxx/test/support/test.support/test_convertible_header.pass.cpp create mode 100644 libcxx/test/support/test.support/test_macros_header_exceptions.fail.cpp create mode 100644 libcxx/test/support/test.support/test_macros_header_exceptions.pass.cpp create mode 100644 libcxx/test/support/test.support/test_macros_header_rtti.fail.cpp create mode 100644 libcxx/test/support/test.support/test_macros_header_rtti.pass.cpp delete mode 100644 libcxx/test/support/test_convertible_header.pass.cpp (limited to 'libcxx/test/support') 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(), "Must be convertible"); + +struct ExplicitDefault { + explicit ExplicitDefault() {} +}; +static_assert(!test_convertible(), "Must not be convertible"); + +struct ImplicitInt { + ImplicitInt(int) {} +}; +static_assert(test_convertible(), "Must be convertible"); + +struct ExplicitInt { + explicit ExplicitInt(int) {} +}; +static_assert(!test_convertible(), "Must not be convertible"); + +struct ImplicitCopy { + ImplicitCopy(ImplicitCopy const&) {} +}; +static_assert(test_convertible(), "Must be convertible"); + +struct ExplicitCopy { + explicit ExplicitCopy(ExplicitCopy const&) {} +}; +static_assert(!test_convertible(), "Must not be convertible"); + +struct ImplicitMove { + ImplicitMove(ImplicitMove&&) {} +}; +static_assert(test_convertible(), "Must be convertible"); + +struct ExplicitMove { + explicit ExplicitMove(ExplicitMove&&) {} +}; +static_assert(!test_convertible(), "Must not be convertible"); + +struct ImplicitArgs { + ImplicitArgs(int, int, int) {} +}; +static_assert(test_convertible(), "Must be convertible"); + +struct ExplicitArgs { + explicit ExplicitArgs(int, int, int) {} +}; +static_assert(!test_convertible(), "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(ptr); // expected-error{{cannot use dynamic_cast}} +#else + A* ptr = new B; + (void)dynamic_cast(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(ptr); +} diff --git a/libcxx/test/support/test_convertible_header.pass.cpp b/libcxx/test/support/test_convertible_header.pass.cpp deleted file mode 100644 index a56b84b4739..00000000000 --- a/libcxx/test/support/test_convertible_header.pass.cpp +++ /dev/null @@ -1,68 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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(), "Must be convertible"); - -struct ExplicitDefault { - explicit ExplicitDefault() {} -}; -static_assert(!test_convertible(), "Must not be convertible"); - -struct ImplicitInt { - ImplicitInt(int) {} -}; -static_assert(test_convertible(), "Must be convertible"); - -struct ExplicitInt { - explicit ExplicitInt(int) {} -}; -static_assert(!test_convertible(), "Must not be convertible"); - -struct ImplicitCopy { - ImplicitCopy(ImplicitCopy const&) {} -}; -static_assert(test_convertible(), "Must be convertible"); - -struct ExplicitCopy { - explicit ExplicitCopy(ExplicitCopy const&) {} -}; -static_assert(!test_convertible(), "Must not be convertible"); - -struct ImplicitMove { - ImplicitMove(ImplicitMove&&) {} -}; -static_assert(test_convertible(), "Must be convertible"); - -struct ExplicitMove { - explicit ExplicitMove(ExplicitMove&&) {} -}; -static_assert(!test_convertible(), "Must not be convertible"); - -struct ImplicitArgs { - ImplicitArgs(int, int, int) {} -}; -static_assert(test_convertible(), "Must be convertible"); - -struct ExplicitArgs { - explicit ExplicitArgs(int, int, int) {} -}; -static_assert(!test_convertible(), "Must not be convertible"); - -int main() { - // Nothing to do -} -- cgit v1.2.3