False Positive for catching type inheriting from std::exception in templates

I reproduced FP in sonarlint with this snippet

template <typename T>
struct MyClass
    class MyException : public std::exception

template <typename S>
void func()
    catch (const typename MyClass<S>::MyException &)

This triggers https://rules.sonarsource.com/cpp/RSPEC-3698 even though MyException clearly inherits from std::exception. As an aside, in our actual code, the similar exception inherits from std::runtime_error, which in turn inherits fro std::exception.

If I take away the template from func, and use MyClass<int>::MyException, then the false positive goes away, and resharper is telling me that the typename becomes redundant.

In the presented version, the typename is required, and clang fails to compile this code without it even though msvc does accept it. Meanwhile, it appears that Sonar is emitting the false positive regardless of whether the typename is present or not.

Hey there.

Which IDE are you using, and which version of SonarLint?

I’m using Visual Studio and Sonarlint is listed as version

Hi @torgeir.skogen,

it is weird I don’t reproduce with the provided snipped on the same version of SonarLint. The rule triggers on the rule’s description example only:

To investigate, can you enable S2260 and check if it triggers on your code? This rule is triggered when the analyzer fails to parse your code.

If S2260 doesn’t show something relevant, it might be related to the environment. Can you generate a reproducer file and share it? I can send you a private message if it contains sensitive information.


I have the file, I can send it to you in a private message.

Thanks @torgeir.skogen for the reproducer. I was able to reproduce it. Here is the ticket: [CPP-3862] - Jira.