Unexpected "Unused functions and methods should be removed" results for static inline functions

Hi SonarQube team,

Here is an unexpected behavior with the “Unused functions and methods should be removed” rule for C.

Observed Behavior
“Unused functions and methods should be removed” violations can be reported within a header file if a .c file includes the header file, but doesn’t call a static inline function defined in the header file. This occurs even if a different .c file includes the same header file and makes a call to the same static inline function.

Why do you believe it’s a false-positive/false-negative?
Defining static inline functions in header files is a valid and common use case for inline functions. A .c file should also not need to call each function declared in a header file that it includes. The expected behavior of the tool is to report violations in a header file only if the static inline function isn’t used ANYWHERE else in the program.

Setup
SonarQube - Developer Edition Version 8.6.1 (build 40680)
compiler - armcc V5.03.0.76

How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
here are snippets of a sample program where the violation can be reported within header.h.

header.h, a header file that defines a static inline function

#ifndef HEADER_H
#define HEADER_H

#include <stdio.h>

static __forceinline void static_inline_function(void)
{
    printf("Hello World");
}

#endif

max.c, a .c file that includes header.h and does use the static inline function

#include "header.h"

int max(int a, int b)
{
    
    static_inline_function();
    
    if(a > b)
        return a;
    else
        return b;
}

hello_world.c, a .c file that includes a header file, but doesn’t use the static inline function declared in the header file.

#include "header.h"

#include "max.h"

int main()
{
    int result = max(5,10);
    return 0;  
}

Hi,

Welcome to the community and thanks for this thorough report!

Can you upgrade to a current version and see if this is still reproducible?

Your upgrade path is:

8.6.1 → 8.9.10 → 9.9.2 → 10.2.1 (last step optional)

You may find these resources helpful:

If you have questions about upgrading, feel free to open a new thread for that here.

 
Ann