See Cognitive Complexity scoring in C source

Dear Support,

I just came across this video about Cognitive Complexity:

Around 16:00min you can see a source code, where the complexity score is visible next to each relevant line. I would like to have that for all our C based projects. (C, C++, C#).

Currently we are running SonarQube v8.0.0.29455. I know there is an update available (v8.1), but because the video is from 2017, and because in the Release Notes of 8.1 there is nothing about Cognitive Complexity, I am wondering is that possible?
In the video the example is a java project. Is this only available for java? Or if I update to 8.1, I will be able to see the Cognitive Complexity scores for each line in a C/C++/C# project as well?


Hi @tcsabina,

what you see in the video is an issue generated when the cognitive complexity of a function is hit. This rule is already available since a long time for C/C++, SonarCFamily 4.6 precisely (Implementation ticket) and the same for C# and many other languages.

The rule is S3776:

You can enable it in your quality profile and eventually modify the default threshold.

Hi Massimo,

Thanks for the fast reply.
I will give it a shot today.
In the meantime, I am wondering about why can I see the CC score of a source file, but cannot see the actual scoring of the lines?

I enabled the rule and made a new scan for one of our projects.
I could see some new violations on the quality profile, and clicking on those new items about cognitive complexity indeed gives me a page with the actual scoring of each line within a function.
So this all looks good.

However if I go to the “Measure” menu in the project, and select Complexity->Cognitive Complexity, I only see a global score for a source file, and not a score for functions within the source file.

Is there a way to see the scoring at least on function level in the Measures overview page somehow?
Or the only way to be able to see the score is to make the rule’s threshold fail?


Hi @tcsabina,

Unfortunately it is not possible.

It is indeed the only way. Why are interested at looking the detailed scoring for functions with low complexity?

With such scoring system, it could come handy to see all the scores for every function. To see if it is already in the warning zone or not.
But probably after spending some time with tackling issues that are there because of this rule, it will be quite clear how to ‘calculate’ the score. And you would be able to identify the ‘complexity’ on the fly, without waiting for the scan…

Hi @tcsabina,

you maybe interested in reading the white paper then: