mclow.lists created this revision. `std::launder` was introduced into c++17 as a compiler optimization barrier. It's something that the compiler 'knows about', and affects codegen.
See https://wg21.link/p0137r1 for more. https://reviews.llvm.org/D40144 Files: include/new test/std/language.support/support.dynamic/ptr.launder/launder.fail.cpp test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp www/cxx1z_status.html
Index: www/cxx1z_status.html =================================================================== --- www/cxx1z_status.html +++ www/cxx1z_status.html @@ -104,6 +104,7 @@ <tr><td><a href="https://wg21.link/p0083r3">p0083r3</a></td><td>LWG</td><td>Splicing Maps and Sets</td><td>Oulu</td><td></td><td></td></tr> <tr><td><a href="https://wg21.link/p0084r2">p0084r2</a></td><td>LWG</td><td>Emplace Return Type</td><td>Oulu</td><td>Complete</td><td>4.0</td></tr> <tr><td><a href="https://wg21.link/p0088r3">p0088r3</a></td><td>LWG</td><td>Variant: a type-safe union for C++17</td><td>Oulu</td><td>Complete</td><td>4.0</td></tr> + <tr><td><a href="https://wg21.link/p0137r1">p0137r1</a></td><td>CWG</td><td>Core Issue 1776: Replacement of class objects containing reference members</td><td>Oulu</td><td>Complete</td><td>6.0</td></tr> <tr><td><a href="https://wg21.link/p0163r0">p0163r0</a></td><td>LWG</td><td>shared_ptr::weak_type</td><td>Oulu</td><td>Complete</td><td>3.9</td></tr> <tr><td><a href="https://wg21.link/p0174r2">p0174r2</a></td><td>LWG</td><td>Deprecating Vestigial Library Parts in C++17</td><td>Oulu</td><td></td><td></td></tr> <tr><td><a href="https://wg21.link/p0175r1">p0175r1</a></td><td>LWG</td><td>Synopses for the C library</td><td>Oulu</td><td></td><td></td></tr> Index: test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp =================================================================== --- test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp +++ 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); +} Index: test/std/language.support/support.dynamic/ptr.launder/launder.fail.cpp =================================================================== --- test/std/language.support/support.dynamic/ptr.launder/launder.fail.cpp +++ test/std/language.support/support.dynamic/ptr.launder/launder.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}} +} Index: include/new =================================================================== --- include/new +++ include/new @@ -46,6 +46,8 @@ new_handler set_new_handler(new_handler new_p) noexcept; new_handler get_new_handler() noexcept; +// 21.6.4, pointer optimization barrier +template <class T> constexpr T* launder(T* p) noexcept; // C++17 } // std void* operator new(std::size_t size); // replaceable @@ -166,6 +168,11 @@ #endif #endif +#if _LIBCPP_STD_VER > 14 +template <class _Tp> +_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY +constexpr _Tp* launder(_Tp* __p) noexcept { return __p;} +#endif } // std #if defined(_LIBCPP_CXX03_LANG)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits