Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BOOST_HAS_BUILTIN_LAUNDER #472

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions doc/html/boost_config/boost_macro_reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,26 @@ <h5>
</p>
</td>
</tr>
<tr>
<td>
<p>
<code class="computeroutput"><span class="identifier">BOOST_HAS_BUILTIN_LAUNDER</span></code>
</p>
</td>
<td>
<p>
Compiler
</p>
</td>
<td>
<p>
The compiler implements the <code class="computeroutput">
<span class="identifier">__builtin_launder()</span></code>
compiler intrinsic that is needed to implement a constexpr
pointer laundering function like <code class="computeroutput">std::launder</code>.
</p>
</td>
</tr>
<tr>
<td>
<p>
Expand Down
4 changes: 4 additions & 0 deletions doc/macro_reference.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,10 @@ standard. The macro is only defined if the feature is present.
[[`BOOST_HAS_BETHREADS`][Platform][
The platform supports BeOS style threads.
]]
[[`BOOST_HAS_BUILTIN_LAUNDER`][Compiler][
The compiler implements the `__builtin_launder()` compiler intrinsic that is needed
to implement a constexpr pointer laundering function like `std::launder`.
]]
[[`BOOST_HAS_CLOCK_GETTIME`][Platform][
The platform has the POSIX API `clock_gettime`.
]]
Expand Down
5 changes: 5 additions & 0 deletions include/boost/config/compiler/gcc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@
#define BOOST_DEPRECATED(msg) __attribute__((deprecated))
#endif

// __builtin_launder intrinsic
#if BOOST_GCC_VERSION >= 70000
# define BOOST_HAS_BUILTIN_LAUNDER
#endif

#ifndef BOOST_COMPILER
# define BOOST_COMPILER "GNU C++ version " __VERSION__
#endif
Expand Down
6 changes: 6 additions & 0 deletions include/boost/config/compiler/visualc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@
#define BOOST_DEPRECATED(msg) __declspec(deprecated)
#endif

// __builtin_launder intrinsic
//The intrinsic is only available in C++17 or later mode
#if (_MSC_VER >= 1910) && defined(_MSVC_LANG) && (_MSVC_LANG > 201402L)
# define BOOST_HAS_BUILTIN_LAUNDER
#endif

//
// TR1 features:
//
Expand Down
7 changes: 7 additions & 0 deletions include/boost/config/detail/suffix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,13 @@ namespace std{ using ::type_info; }
# define BOOST_NO_CXX17_DEDUCTION_GUIDES
#endif

// Generic __builtin_launder intrinsic in case it's not detected by the compiler file
#if !defined(BOOST_HAS_BUILTIN_LAUNDER) && defined(__has_builtin)
# if __has_builtin(__builtin_launder)
# define BOOST_HAS_BUILTIN_LAUNDER
# endif
#endif

//
// Define composite agregate macros:
//
Expand Down
3 changes: 3 additions & 0 deletions test/all/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ test-suite "BOOST_HAS_TWO_ARG_USE_FACET" :
test-suite "BOOST_HAS_BETHREADS" :
[ run ../has_bethreads_pass.cpp ]
[ compile-fail ../has_bethreads_fail.cpp ] ;
test-suite "BOOST_HAS_BUILTIN_LAUNDER" :
[ run ../has_builtin_launder_pass.cpp ]
[ compile-fail ../has_builtin_launder_fail.cpp ] ;
test-suite "BOOST_HAS_CLOCK_GETTIME" :
[ run ../has_clock_gettime_pass.cpp ]
[ compile-fail ../has_clock_gettime_fail.cpp ] ;
Expand Down
29 changes: 29 additions & 0 deletions test/boost_has_builtin_launder.ipp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// (C) Copyright Ion Gaztanaga 2022.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

// See http://www.boost.org/libs/config for most recent version.

// MACRO: BOOST_HAS_BUILTIN_LAUNDER
// TITLE: __builtin_launder
// DESCRIPTION: The platform supports __builtin_launder.

#include <new>

namespace boost_has_builtin_launder {

struct X
{
const int const_int;
};

int test()
{
X original{1};
new (&original) X{2}; //Overwrite X
return __builtin_launder(&original)->const_int == 2 ? 0 : -1; //After laundering, new value should be returned
}

} //namespace boost_has_builtin_launder {

32 changes: 32 additions & 0 deletions test/has_builtin_launder_fail.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// This file was automatically generated on Fri Dec 03 18:03:59 2004
// by libs/config/tools/generate.cpp
// Copyright Ion Gaztanaga 2022.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

// See http://www.boost.org/libs/config for the most recent version.

// Test file for macro BOOST_HAS_BUILTIN_LAUNDER
// This file should not compile, if it does then
// BOOST_HAS_BUILTIN_LAUNDER should be defined.
// See file boost_has_builtin_launder.ipp for details

// Must not have BOOST_ASSERT_CONFIG set; it defeats
// the objective of this file:
#ifdef BOOST_ASSERT_CONFIG
# undef BOOST_ASSERT_CONFIG
#endif

#include <boost/config.hpp>

#ifndef BOOST_HAS_BUILTIN_LAUNDER
#include "boost_has_builtin_launder.ipp"
#else
#error "this file should not compile"
#endif

int main( int, char *[] )
{
return boost_has_builtin_launder::test();
}
34 changes: 34 additions & 0 deletions test/has_builtin_launder_pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// This file was automatically generated on Fri Dec 03 18:03:59 2004
// by libs/config/tools/generate.cpp
// Copyright Ion Gaztanaga 2022.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

// See http://www.boost.org/libs/config for the most recent version.

// Test file for macro BOOST_HAS_BUILTIN_LAUNDER
// This file should compile, if it does not then
// BOOST_HAS_BUILTIN_LAUNDER should not be defined.
// See file boost_has_builtin_launder.ipp for details

// Must not have BOOST_ASSERT_CONFIG set; it defeats
// the objective of this file:
#ifdef BOOST_ASSERT_CONFIG
# undef BOOST_ASSERT_CONFIG
#endif

#include <boost/config.hpp>
#include "test.hpp"

#ifdef BOOST_HAS_BUILTIN_LAUNDER
#include "boost_has_builtin_launder.ipp"
#else
namespace boost_has_builtin_launder = empty_boost;
#endif

int main( int, char *[] )
{
return boost_has_builtin_launder::test();
}