-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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_THROW
, EXPECT_NO_THROW
, ASSERT_THROW
, and ASSERT_NO_THROW
don't play nice with [[nodiscard]]
#4679
Comments
I for one would rather The statement inside the macro can also be assignment, so you can do: ASSERT_NO_THROW(std::ignore = a_function_that_throws());
// or
int result{};
ASSERT_NO_THROW(result = a_function_that_throws());
EXPECT_EQ(result, 1); |
EXPECT_NO_THROW
and ASSERT_NO_THROW
don't play nice with [[nodiscard]]
EXPECT_THROW
, EXPECT_NO_THROW
, ASSERT_THROW
, and ASSERT_NO_THROW
don't play nice with [[nodiscard]]
@dkaszews Fair, I an argument could be made for In the throwing case, the return value is truly irrelevant, so gtest should handle that gracefully for us. |
@Jacobfaib Sure, Question is, are throwing functions with The only case I can thing of is something like |
Very common, at least in my experience. We use For example, you can have a factory function that validates the inputs before constructing the widget. This is both |
Does the feature exist in the most recent commit?
Tested on
v1.13.0
, but the same problem also exists at head:googletest/googletest/include/gtest/internal/gtest-internal.h
Lines 1367 to 1373 in 79219e2
where
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_()
expands asgoogletest/googletest/include/gtest/internal/gtest-internal.h
Lines 1312 to 1316 in 79219e2
Why do we need this feature?
I can work around it by doing
but I feel like gtest should render this nicety for me.
Describe the proposal.
Wrap
statement
instatic_cast<void>(statement)
orstd::ignore = statement
. The former is probably more general.Is the feature specific to an operating system, compiler, or build system version?
No.
The text was updated successfully, but these errors were encountered: