Skip to content

Conversation

gennaroprota
Copy link

@gennaroprota gennaroprota commented Oct 9, 2025

Reason: Common hygiene for multi-line macros. Makes things like

if (condition)
    BOOST_TEST_THROWS(...);
else
    ...

work correctly. Also, it doesn't generate an empty statement (which compilers may warn about) when the user adds a semicolon (which they usually do).

@pdimov
Copy link
Member

pdimov commented Oct 9, 2025

This is technically a breaking change because the semicolon is now required, whereas it wasn't before. But it looks like all our uses have a semicolon.

The backslash at the last line shouldn't be present. We should remove it from BOOST_TEST_THROWS, instead of adding it to BOOST_TEST_NO_THROW.

@gennaroprota
Copy link
Author

The backslash at the last line shouldn't be present. We should remove it from BOOST_TEST_THROWS, instead of adding it to BOOST_TEST_NO_THROW.

I thought the convention was to terminate with a // comment:

last_line    \
//

Didn't notice this hadn't been done for BOOST_TEST_NO_THROW().

…EST_NO_THROW()

Reason: Common hygiene for multi-line macros. Makes things like

if (condition)
    BOOST_TEST_THROWS(...);
else
    ...

work correctly. Also, it doesn't generate an empty statement (which
compilers may warn about) when the user adds a semicolon (which they
usually do).
@gennaroprota gennaroprota force-pushed the fix/use_do_while_false_for_boost_test_throws_and_boost_test_no_throw branch from 459d57d to 8a352e2 Compare October 9, 2025 17:01
@pdimov
Copy link
Member

pdimov commented Oct 9, 2025

libs\core\test\lightweight_test_test.cpp(105) : warning C4127: conditional expression is constant

Yeah :-/

@gennaroprota
Copy link
Author

Sigh. Which version of MSVC? I don't get that warning with MSVC 2022 and /Wall.

@pdimov
Copy link
Member

pdimov commented Oct 10, 2025

Up to msvc-12.0 according to Appveyor.

@gennaroprota
Copy link
Author

Hmm. We might try with do {} while (0), which is probably more common and might be special-cased, even in old versions of MSVC.

@Lastique
Copy link
Member

Lastique commented Oct 10, 2025

Just add _Pragma("warning(disable: 4127)") to the macros. With the corresponding push and pop pragmas as well.

@gennaroprota gennaroprota force-pushed the fix/use_do_while_false_for_boost_test_throws_and_boost_test_no_throw branch 2 times, most recently from 0cfc658 to d30689c Compare October 13, 2025 17:38
@pdimov
Copy link
Member

pdimov commented Oct 13, 2025

BOOST_TEST_xxx is a public macro name. Please use BOOST_LWT_DETAIL_xxx for implementation details.

@gennaroprota gennaroprota force-pushed the fix/use_do_while_false_for_boost_test_throws_and_boost_test_no_throw branch from d30689c to a931f06 Compare October 13, 2025 18:11
@Lastique
Copy link
Member

Lastique commented Oct 13, 2025

One other alternative we could try is for (;;) { x; break; }.

@gennaroprota
Copy link
Author

That doesn't play well with the semicolon (the one after the macro invocation).

@gennaroprota gennaroprota force-pushed the fix/use_do_while_false_for_boost_test_throws_and_boost_test_no_throw branch 2 times, most recently from 48268d5 to 7ffb4f8 Compare October 14, 2025 07:30
#define BOOST_TEST_ALL_WITH(begin1, end1, begin2, end2, predicate) ( ::boost::detail::test_all_with_impl(BOOST_LIGHTWEIGHT_TEST_OSTREAM, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, begin1, end1, begin2, end2, predicate) )


#if !defined(BOOST_MSVC) || (BOOST_MSVC > 1900)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: better spell the second comparison as BOOST_MSVC >= x, where x is the oldest version we know works. This saves from some SP or Update with a version that is higher than 1900 but still issues the warning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1900 looks wrong, 1900 is msvc 14.0 unpatched. Should be >= 1900.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I test if the compiler is not MSVC or is MSVC > 2015. I think 2015 still emits the warning for do {} while (false) (while MSVC 2017 doesn't), right? I might change the second test to >= 1910 though, as Lastique suggested.

MSVC 2015 == 1900
MSVC 2017 == 1910

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, msvc-14.0 doesn't emit the warning. But if it did, >= 1910 would be the correct check.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry. Too many irons in the fire :-). Fixed, now.

@gennaroprota gennaroprota force-pushed the fix/use_do_while_false_for_boost_test_throws_and_boost_test_no_throw branch from 7ffb4f8 to 4ee817d Compare October 14, 2025 13:20
@pdimov
Copy link
Member

pdimov commented Oct 14, 2025

Everything fails, probably because you're missing a semicolon here BOOST_LWT_DETAIL_DO_WHILE_FALSE(static_cast<void>(0)).

@pdimov
Copy link
Member

pdimov commented Oct 14, 2025

(void)0; is probably a more idiomatic form of a null statement, despite the C cast.

@gennaroprota gennaroprota force-pushed the fix/use_do_while_false_for_boost_test_throws_and_boost_test_no_throw branch from 4ee817d to 1ed1e04 Compare October 14, 2025 13:29
@gennaroprota
Copy link
Author

Do you prefer that? (Why?)

@pdimov
Copy link
Member

pdimov commented Oct 14, 2025

It's idiomatic because that's what assert typically uses.

Nowadays (void) is also emerging as the idiomatic way to silence nodiscard warnings.

@gennaroprota
Copy link
Author

I don't have a strong opinion about that. I can change it, if you like. (About assert(), though, I think it's (void) because it's common to C.)

@pdimov
Copy link
Member

pdimov commented Oct 14, 2025

Yes please, let's go with (void). I've always found static_cast<void> somewhat pretentious, and it does require parentheses around the expression which is also a bit jarring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants