How to ENABLE unused parameter warnings

jcolebaker
Posts: 60
Joined: Thu Mar 18, 2021 12:23 am

How to ENABLE unused parameter warnings

Postby jcolebaker » Thu May 06, 2021 12:07 am

Hi,

For the sake of good coding practice, we would like to enable compiler warnings for unused function parameters in GCC.

According to the build system guide, we should be able to use idf_build_set_property(COMPILE_OPTIONS "-Wall" APPEND) or similar in the project CMakeLists.txt file. In fact, -Wall should already be on and this should warn about unused parameters.

I don't think it does, because I have this in a component (task function which doesn't require an argument)*:

[Codebox]
static void DemoTask(void *arg)
{
// "arg" is not used.
...
}
[/Codebox]

This builds without any errors or warnings.

I tried adding the following to the CMakeLists.txt in the root directory of the project, and then also in the CMakeLists.txt for the component:

Code: Select all

idf_build_set_property(COMPILE_OPTIONS "-Wall" "-Wextra" "-Wunused-parameter" "-Werror" APPEND)
Each time I did a clean build, but it always builds without errors or warnings.

Is this the correct way to change the compiler options? Ideas?


* Nb: If the warnings did work, we would obviously need to add an "UNUSED(...)" macro for genuinely unused parameters required by the API, e.g. the task function above. That is our preferred option, so that accidental unused parameters can be found.

Who is online

Users browsing this forum: Bing [Bot] and 109 guests