C++17 if constexpr not detected by rule "Control structures should use curly braces"

Continuing the discussion from C++17 if constexpr are tagged as code smell:

The linked ticket seems to handle a different rule. We are using version 9.4, where if constexpr is still flagged with:

Add curly braces around the nested statement(s) in this “if” block.

Hey there.

v9.4 is a bit over a year old now (and has been EOL since v9.5 came out). Can you check that the issue can still be reproduced on v9.9 LTS?

Hi @Colin,
Thanks for your response. I’ll ask our support team to update the version and check again.

hi @max.sch,

Just to clarify your title says not detected but the description says that we raise an issue.
I expect our analyzer to detect the issue. I don’t see why if constexpr is different than if when it comes to adding curly braces.

For the other post you linked, it was a false positive. In your case, it isn’t.

Thanks,

Hi @Abbas,
Thanks for the response. I checked again for details here.
Seems like the problem may be related to combination with lambdas. Something like this:

auto callback = [](auto param)
{
    if constexpr (...)
    {
//  ^ SonarQube complains about missing curly braces here
    }
}

Unfortunately I fail to produce the issue with IDE integration. Even at the place where the server detects the issue. So I also fail to create a small example to produce the issue.
Let’s see if findings still exists after update.

@max.sch thanks for the clarification.
No need for the manual work. If it is still there after the update, I will send you instructions to generate an automatic reproducer from the server.