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

useless-cast warning from THROW macro family #2520

Closed
HazardyKnusperkeks opened this issue Sep 14, 2022 · 1 comment · Fixed by #2521
Closed

useless-cast warning from THROW macro family #2520

HazardyKnusperkeks opened this issue Sep 14, 2022 · 1 comment · Fixed by #2521

Comments

@HazardyKnusperkeks
Copy link
Contributor

Describe the bug
We get the following error message (with -Werror) when using REQUIRE_NOTHROW on a void function.

.../Catch2/src/catch2/internal/catch_test_macro_impl.hpp:79:13: error: useless cast to type 'void' [-Werror=useless-cast]
   79 |             static_cast<void>(__VA_ARGS__); \
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../Catch2/src/catch2/catch_test_macros.hpp:128:34: note: in expansion of macro 'INTERNAL_CATCH_NO_THROW'
  128 |   #define REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ )
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~
mycode.cpp:47:41: note: in expansion of macro 'REQUIRE_NOTHROW'

Expected behavior
No Warning.

Reproduction steps

#include <catch2/catch_test_macros.hpp>

void op();

TEST_CASE("") {
    REQUIRE_NOTHROW(op());
}

Although I was not able to reproduce it on godbolt.

Platform information:

  • OS: Windows 10
  • Compiler+version: g++.exe (Rev1, Built by MSYS2 project) 12.2.0
  • We have -Wuseless-cast in our warning list
  • Catch version: v3.1.0

Additional context
We just migrated from Catch 2.13.8 with the single include. Before the Code produced no warning.

I'm also willing to fix this with

                if constexpr ( std::is_same_v<decltype( __VA_ARGS__ ),      \
                                              void> ) {                     \
                    __VA_ARGS__;                                            \
                } else {                                                    \
                    static_cast<void>( __VA_ARGS__ );                       \
                }                                                           \
@HazardyKnusperkeks
Copy link
Contributor Author

Okay that doesn't solve the warning. So one would need to suppress it?

HazardyKnusperkeks added a commit to OttoKuennecke/Catch2 that referenced this issue Sep 14, 2022
horenmar pushed a commit that referenced this issue Sep 22, 2022
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 a pull request may close this issue.

1 participant