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

[Bug]: GTEST_FATAL_FAILURE_ and GTEST_SKIP_ return void expression #4625

Open
hurzelchen opened this issue Oct 8, 2024 · 1 comment
Open

Comments

@hurzelchen
Copy link

Describe the issue

The internal macros GTEST_FATAL_FAILURE_ and GTEST_SKIP_ return the void expression GTEST_MESSAGE_.

I would expect them to call GTEST_MESSAGE_ and then return.

Steps to reproduce the problem

Run clazy static code analyzer on simple TestCase that uses one of the ASSERT_ macros.

It will e.g. report

main.cpp:39:5: warning: Returning a void expression [-Wclazy-returning-void-expression]
    ASSERT_TRUE(true);
    ^
/usr/src/googletest/googletest/include/gtest/gtest.h:1990:32: note: expanded from macro 'ASSERT_TRUE'
#define ASSERT_TRUE(condition) GTEST_ASSERT_TRUE(condition)
                               ^
/usr/src/googletest/googletest/include/gtest/gtest.h:1973:23: note: expanded from macro 'GTEST_ASSERT_TRUE'
                      GTEST_FATAL_FAILURE_)

What version of GoogleTest are you using?

1.11.0

What operating system and version are you using?

Ubuntu 22.04.5

What compiler and version are you using?

clang 14.0 with clazy 1.11 plugin

What build system are you using?

cmake 3.24.4

Additional context

No response

@Andrewshin-7th-technology-student

The issue you're experiencing is due to a change in the behavior of the GTEST_FATAL_FAILURE_ and GTEST_SKIP_ macros in GoogleTest 1.11.0.

In previous versions of GoogleTest, these macros would call GTEST_MESSAGE_ and then return. However, in GoogleTest 1.11.0, these macros now return the void expression GTEST_MESSAGE_ instead of calling it.

This change is causing the clazy static code analyzer to report a warning about returning a void expression.

To fix this issue, you can try the following:

Update clazy to a version that is compatible with GoogleTest 1.11.0: The clazy plugin is not compatible with the new behavior of the GTEST_FATAL_FAILURE_ and GTEST_SKIP_ macros in GoogleTest 1.11.0. You can try updating clazy to a version that is compatible with GoogleTest 1.11.0.
Suppress the warning: You can suppress the warning by adding the following line to your CMakeLists.txt file:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-clazy-returning-void-expression")

This will disable the warning about returning a void expression. 3. Use a different version of GoogleTest: If you're not required to use GoogleTest 1.11.0, you can try using a previous version of GoogleTest that does not have this issue. 4. Modify the clazy plugin: If you're unable to update clazy or use a different version of GoogleTest, you can try modifying the clazy plugin to ignore this warning. You can do this by adding the following line to the clazy configuration file:

set(clazy:suppress-warnings "returning-void-expression")

good luck fixing your problem! :D

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

No branches or pull requests

2 participants