Potential False Positive in c:S810 With Ternary Operator

Running SonarQube with SonarScanner
The original issue is in the parameter of a function call but I was able to reproduce in a simple assignment test:

        char z = 'A';
        char y = (z? 'a' : 'b');

The second line raises an issue “Target type is a plain char and should not be used to store numeric values.” This is unexpected according to the rule documentation and the fact that the assignment above it works.

I was unable to find an exact explanation for this behaviour in the C standard (checked C99) and GCC and Clang-10/12 neither throw warnings when compiled with -Wall.

Hello @Adrianh ,

Thank you for the report!
Indeed, you’re right this seems to be a false positive. I have created a ticket to fix it: CPP-3865

Have a nice day

1 Like

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