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

CMake: Enable -Werror=unused-parameter flag to treat unused-parameter warnings as errors #2313

Open
wants to merge 2 commits into
base: unstable
Choose a base branch
from

Conversation

VasuDevrani
Copy link
Contributor

for #2266
this will output unused-parameters warnings as errors.

Screenshot 2024-05-15 133023

@torwig
Copy link
Contributor

torwig commented May 15, 2024

@VasuDevrani Should we also fix those errors in the scope of this PR?

@VasuDevrani
Copy link
Contributor Author

@VasuDevrani Should we also fix those errors in the scope of this PR?

maybe yes (but they are a lot), I think the CI failing because of those.

@PragmaTwice
Copy link
Member

Yeah we should fix them otherwise the PR will be blocked by CI failure.

You can use the attribute [[maybe_unused]].

@VasuDevrani
Copy link
Contributor Author

You can use the attribute [[maybe_unused]].

Wouldn't it be better to drop the unused parameter and keep the type only

virtual Status ToNumber(int64_t*) const { return {Status::NotOK, "not supported"}; }
virtual Status ToBool(bool*) const { return {Status::NotOK, "not supported"}; }

@mapleFU
Copy link
Member

mapleFU commented May 16, 2024

Wouldn't it be better to drop the unused parameter and keep the type only

It's also ok here but keeping a name might be more specific?

@PragmaTwice
Copy link
Member

PragmaTwice commented May 16, 2024

You can use the attribute [[maybe_unused]].

Wouldn't it be better to drop the unused parameter and keep the type only

virtual Status ToNumber(int64_t*) const { return {Status::NotOK, "not supported"}; }
virtual Status ToBool(bool*) const { return {Status::NotOK, "not supported"}; }

There's some information in the names, so we'd better to keep them.

@VasuDevrani
Copy link
Contributor Author

Two more concerns, then I'll move forward with [[maybe_unused]]:

  • it can make code a bit unreadable (especially if there's multiple unused params together)
void performOperation(const Config& config, [[maybe_unused]] int param1, [[maybe_unused]] double param2, [[maybe_unused]] const std::string& param3) {
    // Use only the 'config' parameter
    if (config.isEnabled()) {
        // Perform the operation
        // ...
    }
}

VS

void performOperation(const Config& config, int, double, const std::string&) {
    // Use only the 'config' parameter
    if (config.isEnabled()) {
        // Perform the operation
        // ...
    }
}
  • supported for cpp 17+ (then again project cmake sets it at 17)

@mapleFU
Copy link
Member

mapleFU commented May 16, 2024

We already uses C++17, yeah?

@VasuDevrani
Copy link
Contributor Author

We already uses C++17, isn't we?

yes

@@ -273,6 +273,8 @@ else()
target_compile_definitions(kvrocks_objs PUBLIC METADATA_ENCODING_VERSION=0)
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=unused-parameter")
Copy link

Choose a reason for hiding this comment

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

Setting CMAKE_CXX_FLAGS globally is an anti-pattern in CMake.
Maybe the same effect can be achieved with

target_compile_options(kvrocks_objs PUBLIC -Werror=unused-parameter)

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.

None yet

5 participants