From 76061d91d4b695d3a3644196c860e5feb0e6f0bf Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Sun, 14 Jul 2024 07:04:23 -0400 Subject: [PATCH] Move compile test to separate source file --- test/Jamfile.v2 | 1 + test/empty_value_nested_test.cpp | 45 ++++++++++++++++++++++++++++++++ test/empty_value_test.cpp | 34 ------------------------ 3 files changed, 46 insertions(+), 34 deletions(-) create mode 100644 test/empty_value_nested_test.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index e9a1d07d..8c27813b 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 empty_value_nested_test.cpp ; compile-fail empty_value_compile_fail_casting.cpp ; run quick_exit_test.cpp ; diff --git a/test/empty_value_nested_test.cpp b/test/empty_value_nested_test.cpp new file mode 100644 index 00000000..7c011a5b --- /dev/null +++ b/test/empty_value_nested_test.cpp @@ -0,0 +1,45 @@ +/* +Copyright 2024 Braden Ganetsky +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include + +/* +Tests workaround for MSVC bug: +https://developercommunity.visualstudio.com/t/Compiler-bug:-Incorrect-C2247-and-C2248/10690025 +*/ +template +struct derived + : boost::empty_value { + typedef typename boost::empty_value::type type; + derived(boost::empty_init_t e) + : boost::empty_value(e) { } +}; + +struct outer { + struct inner_empty { }; + struct inner_non_empty { + inner_non_empty() + : value() { } + int value; + }; +}; + +void test() +{ + const boost::empty_value x1(boost::empty_init); + (void)x1; + const boost::empty_value x2(boost::empty_init); + (void)x2; + const boost::empty_value x3(boost::empty_init); + (void)x3; + const derived x4(boost::empty_init); + (void)x4; + const derived x5(boost::empty_init); + (void)x5; + const derived x6(boost::empty_init); + (void)x6; +} diff --git a/test/empty_value_test.cpp b/test/empty_value_test.cpp index 44dba4c4..b7cf7961 100644 --- a/test/empty_value_test.cpp +++ b/test/empty_value_test.cpp @@ -63,40 +63,6 @@ void test_type() BOOST_TEST(v2.get().value() == 6); } -template -struct derived : boost::empty_value { - typedef typename boost::empty_value::type type; - derived(boost::empty_init_t e) : boost::empty_value(e) {} -}; - -struct outer { - struct inner_empty {}; - struct inner_non_empty { - inner_non_empty() : value() {} - int value; - }; -}; - -void test_derived_compile() -{ - // This is testing the workaround to an MSVC bug when T is a nested class. - // See https://developercommunity.visualstudio.com/t/Compiler-bug:-Incorrect-C2247-and-C2248/10690025 - - const boost::empty_value x1(boost::empty_init); - const boost::empty_value x2(boost::empty_init); - const boost::empty_value x3(boost::empty_init); - const derived x4(boost::empty_init); - const derived x5(boost::empty_init); - const derived x6(boost::empty_init); - - (void)x1; - (void)x2; - (void)x3; - (void)x4; - (void)x5; - (void)x6; -} - int main() { test_int();