From d01b4e94cc72abaae859d1fe739ca6b81e2cfa04 Mon Sep 17 00:00:00 2001 From: Braden Ganetsky Date: Mon, 24 Jun 2024 13:15:05 -0500 Subject: [PATCH] Write test for empty_value private inheritance --- test/Jamfile.v2 | 1 + test/empty_value_compile_fail_casting.cpp | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 test/empty_value_compile_fail_casting.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 5df9242..e9a1d07 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -226,6 +226,7 @@ run empty_value_test.cpp ; run empty_value_size_test.cpp ; run empty_value_final_test.cpp ; run empty_value_constexpr_test.cpp ; +compile-fail empty_value_compile_fail_casting.cpp ; run quick_exit_test.cpp ; run-fail quick_exit_fail.cpp ; diff --git a/test/empty_value_compile_fail_casting.cpp b/test/empty_value_compile_fail_casting.cpp new file mode 100644 index 0000000..e4cac42 --- /dev/null +++ b/test/empty_value_compile_fail_casting.cpp @@ -0,0 +1,20 @@ +// Copyright 2024 Braden Ganetsky +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include + +struct empty {}; + +// This test ensures private inheritance of `boost::empty_value` for empty `T`. +// With public inheritance, `boost::empty_value*` could cast to `empty*`. +void test_empty_not_convertible_to_base() +{ + const boost::empty_value x(boost::empty_init); + const empty* x2 = static_cast(&x); + (void)x2; +} + +int main() +{ +}