From aa0e236289a6643641c6d268deb69e0013d5112a Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 22 Nov 2017 19:49:03 +0000 Subject: 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 --- .../ptr.launder/launder.nodiscard.fail.cpp | 27 +++++++++++++++++ .../support.dynamic/ptr.launder/launder.pass.cpp | 35 ++++++++++++++++++++++ .../ptr.launder/launder.types.fail.cpp | 34 +++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp create mode 100644 test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp create mode 100644 test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp (limited to 'test') 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. +// +//===----------------------------------------------------------------------===// + +// + +// template 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 +#include + +#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. +// +//===----------------------------------------------------------------------===// + +// + +// template constexpr T* launder(T* p) noexcept; + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +#include +#include + +#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::value, ""); + static_assert(std::is_same::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. +// +//===----------------------------------------------------------------------===// + +// + +// template 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 +#include + +#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"}} +} -- cgit v1.2.3