cpp:S856 triggers on conversion to typedef of void *

False positive present in Sonarqube version 8.9.1

This rule as described here Rules explorer Should have an exception when converting to void *.

However, it seems like it will trigger anyway when converting to a type alias of void *.

This code is effectively reproducing the issue, and triggers this warning.

using vptr = void *;

int func(vptr ptr);


int main()
{
    int a = 1;
    func(static_cast<vptr>(&a));
}

Note that using

func(&a);

Also triggers the same warning.

Meanwhile, this does not trigger the warning:

using vptr = void *;

int func(vptr ptr);


int main()
{
    int a = 1;
    void *p = &a
    func(p);
}

It seems logical for a type alias of void * to get the same exception as the void * itself.

I agree with you, it looks like an oversight.

I created CPP-3241 to correct this.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.