diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2017-11-22 19:49:03 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2017-11-22 19:49:03 +0000 |
commit | aa0e236289a6643641c6d268deb69e0013d5112a (patch) | |
tree | 4e44eab88717d64a82eab8f34ead8ef142d2ecf9 /test | |
parent | bd858589df5f68c1d7521b882b18c8b72a4c86e7 (diff) |
Implement p0137r1 - std::launder. Reviewed as https://reviews.llvm.org/D40144
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@318864 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
3 files changed, 96 insertions, 0 deletions
diff --git a/test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp b/test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp new file mode 100644 index 000000000..1c75e561d --- /dev/null +++ b/test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp @@ -0,0 +1,27 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <new> + +// template <class T> constexpr T* launder(T* p) noexcept; + +// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 +// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8 + +#include <new> +#include <cassert> + +#include "test_macros.h" + +int main () +{ + int *p = nullptr; + std::launder(p); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} +} diff --git a/test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp b/test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp new file mode 100644 index 000000000..1aa462957 --- /dev/null +++ b/test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <new> + +// template <class T> constexpr T* launder(T* p) noexcept; + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +#include <new> +#include <cassert> + +#include "test_macros.h" + +constexpr int gi = 5; +constexpr float gf = 8.f; + +int main() { + static_assert(std::launder(&gi) == &gi, "" ); + static_assert(std::launder(&gf) == &gf, "" ); + + const int *i = &gi; + const float *f = &gf; + static_assert(std::is_same<decltype(i), decltype(std::launder(i))>::value, ""); + static_assert(std::is_same<decltype(f), decltype(std::launder(f))>::value, ""); + + assert(std::launder(i) == i); + assert(std::launder(f) == f); +} diff --git a/test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp b/test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp new file mode 100644 index 000000000..71f5e4588 --- /dev/null +++ b/test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp @@ -0,0 +1,34 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <new> + +// template <class T> constexpr T* launder(T* p) noexcept; +// The program is ill-formed if T is a function type or cv void. + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +#include <new> +#include <cassert> + +#include "test_macros.h" + +void foo() {} + +int main () +{ + void *p = nullptr; + (void) std::launder(( void *) nullptr); + (void) std::launder((const void *) nullptr); + (void) std::launder(( volatile void *) nullptr); + (void) std::launder((const volatile void *) nullptr); // expected-error-re@new:* 4 {{static_assert failed{{.*}} "can't launder cv-void"}} + + (void) std::launder(foo); // expected-error-re@new:* 1 {{static_assert failed{{.*}} "can't launder functions"}} +} |