Multiple warnings on same line might not be shown
Environment
- Operating System (e.g. Ubuntu 16.04 x64): Windows 10 Version 1909
- IDE Version (e.g. CLion 2016.3.2): Clion 2020.1
- Cppcheck executable version (
cppcheck --version): 1.90 - Cppcheck plugin version: 1.4.2
- Exact strings used in cppcheck plugin options:
- cppcheck options: --enable=all --inconclusive --language=c++
Steps to reproduce the behaviour
This code
#include <iostream>
class A
{
public:
A():m_pi(new int[12]){}
~A(){throw "~A() dtor;";delete [] m_pi;}
private:
int *m_pi;
};
Produces four warnings
/mnt/s/GitHub/cppcheck-fw/lib/__test.cpp:6:6: warning: Class 'A' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s). [noCopyConstructor]
A():m_pi(new int[12]){}
^
/mnt/s/GitHub/cppcheck-fw/lib/__test.cpp:6:6: warning: Class 'A' does not have a operator= which is recommended since it has dynamic memory/resource allocation(s). [noOperatorEq]
A():m_pi(new int[12]){}
^
/mnt/s/GitHub/cppcheck-fw/lib/__test.cpp:7:7: warning: Class A is not safe, destructor throws exception [exceptThrowInDestructor]
~A(){throw "~A() dtor;";delete [] m_pi;}
^
/mnt/s/GitHub/cppcheck-fw/lib/__test.cpp:7:26: style: Statements following return, break, continue, goto or throw will never be executed. [unreachableCode]
~A(){throw "~A() dtor;";delete [] m_pi;}
^
The warnings on line 6 will both be shown, but line 7 omits the style one.

For what it's worth, we do capture and send multiple problem reports back up to CLion. If you run Analyze | Inspect Code you will see multiple warnings even for a single line. This might be a limitation with the plugin API we are using.
That's possible. I haven't looked at it at all. I first need to be able to understand how to test a development plugin in CLion.
See if #44 helps at all.
I was able to build the plugin before based on 2020.1 or 2020.2. Somehow the latest SDK from 2020.3 EAP isn't working anymore.
S:\idea\clion-cppcheck\src\com\github\johnthagen\cppcheck\Configuration.java:3:36
java: cannot access com.intellij.openapi.options.Configurable
bad class file: /C:/Program Files/JetBrains/IntelliJ IDEA Community Edition 203.4818.26/lib/platform-api.jar!/com/intellij/openapi/options/Configurable.class
class file has wrong version 55.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
But when I try to re-add the plugin SDK I get errors. So it might actually be a bug in IDEA. Will try to take a deeper look soon.
For what it's worth, I am using 2020.2.3 currently successfully.
I think this issue is actually possibly invalid. If you hold your cursor on the gutter, you can actually see multiple warnings. I think this is just how IntelliJ products work. I'm guessing that IntelliJ perhaps only shows the most severe warning when you hover over the text, but will show multiple in the gutter and Analyze | Inspect Code
Closing as invalid as this appears to be normal behavior for IntelliJ-based tools.
Please re-open it. I want to investigate this at least a bit as this should be working. Recently I have just been logging issues and not following up on them for lack of time.
Other parts of CLion can also show multiple issues on the same line - heck, it's actually bound to multiple part of the same line depending on the index. Maybe I missed something, the plugin needs to report it differently or it's even a bug in CLion.
Thanks - there's still the invalid tag though.
Seems like this is an issue within CLion - https://youtrack.jetbrains.com/issue/CPP-22712. I think this issue should stay open until it is resolved upstream.
FYI I also found some additional issues in CLion and Cppcheck while researching this.
BTW I am able to build the plugin again. Turns out I had to switch to JDK 11 as the SDK. The IDEA error message even says that but I somehow overlooked that in my first few attempts. I also found the Install plugin from disk option so I can fully test my changed now. :)
I ran into this again.
#include <string>
static void f()
{
std::string s6(0);
}
/mnt/s/___temp/input.cpp:5:17: error: Null pointer dereference [nullPointer]
std::string s6(0);
^
/mnt/s/___temp/input.cpp:5:19: style: Variable 's6' is assigned a value that is never used. [unreadVariable]
std::string s6(0);
^
<error id="nullPointer" severity="error" msg="Null pointer dereference" verbose="Null pointer dereference" cwe="476" file0="C:/Users/username/AppData/Local/Temp/ZF4azrQ5_input.cpp">
<location file="C:\Users\username\AppData\Local\Temp\ZF4azrQ5_input.cpp" line="5" column="17" info="Null pointer dereference"/>
</error>
<error id="unreadVariable" severity="style" msg="Variable 's6' is assigned a value that is never used." verbose="Variable 's6' is assigned a value that is never used." cwe="563" file0="C:/Users/username/AppData/Local/Temp/ZF4azrQ5_input.cpp">
<location file="C:\Users\username\AppData\Local\Temp\ZF4azrQ5_input.cpp" line="5" column="19"/>
<symbol>s6</symbol>
</error>
