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

[FR]: EXPECT_NO_THROW and ASSERT_NO_THROW don't play nice with [[nodiscard]] #4679

Open
Jacobfaib opened this issue Dec 11, 2024 · 0 comments

Comments

@Jacobfaib
Copy link

Jacobfaib commented Dec 11, 2024

Does the feature exist in the most recent commit?

Tested on v1.13.0, but the same problem also exists at head:

#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (::testing::internal::TrueWithString gtest_msg{}) { \
bool gtest_caught_expected = false; \
try { \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
} catch (expected_exception const&) { \

where GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_() expands as

#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
if (::testing::internal::AlwaysTrue()) { \
statement; \
} else /* NOLINT */ \
static_assert(true, "") // User must have a semicolon after expansion.

Why do we need this feature?

I can work around it by doing

[[nodiscard]] int a_function_that_throws();

ASSERT_NO_THROW(static_cast<void>(a_function_that_throws()), ...)

but I feel like gtest should render this nicety for me.

Describe the proposal.

Wrap statement in static_cast<void>(statement) or std::ignore = statement. The former is probably more general.

Is the feature specific to an operating system, compiler, or build system version?

No.

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

No branches or pull requests

1 participant