Skip to content

Commit

Permalink
Write test for empty_value private inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
k3DW committed Jun 24, 2024
1 parent 79879ec commit 17a16d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down
22 changes: 22 additions & 0 deletions test/empty_value_compile_fail_casting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2024 Braden Ganetsky
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/core/empty_value.hpp>

struct empty {};

// This test ensures private inheritance of `boost::empty_value<T>` for empty `T`.
// With public inheritance, `boost::empty_value<empty>*` could cast to `empty*`.
void test_empty_not_convertible_to_base_helper(const empty*)
{
}
void test_empty_not_convertible_to_base()
{
const boost::empty_value<empty> x(boost::empty_init);
test_empty_not_convertible_to_base_helper(&x);
}

int main()
{
}

0 comments on commit 17a16d6

Please sign in to comment.