diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2017-11-22 22:49:03 +0300 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2017-11-22 22:49:03 +0300 |
commit | 9180eb1f4ab96481413e93d35f35c3685de3084c (patch) | |
tree | cd567a3da8ebf76d616d8dbc2ea2111ae725409c /libcxx/test/std | |
parent | 374cff69e0c54989e8e8a7426b74b0b248c4885d (diff) |
Implement p0137r1 - std::launder. Reviewed as https://reviews.llvm.org/D40144
llvm-svn: 318864
Diffstat (limited to 'libcxx/test/std')
3 files changed, 96 insertions, 0 deletions
diff --git a/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp b/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp new file mode 100644 index 000000000000..1c75e561d7c7 --- /dev/null +++ b/libcxx/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/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp b/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp new file mode 100644 index 000000000000..1aa462957c8b --- /dev/null +++ b/libcxx/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/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp b/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp new file mode 100644 index 000000000000..71f5e4588b82 --- /dev/null +++ b/libcxx/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"}} +} |