Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple warnings on same line might not be shown #37

Open
firewave opened this issue Apr 19, 2020 · 11 comments
Open

Multiple warnings on same line might not be shown #37

firewave opened this issue Apr 19, 2020 · 11 comments

Comments

@firewave
Copy link
Collaborator

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.

image

@johnthagen
Copy link
Owner

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.

@firewave
Copy link
Collaborator Author

firewave commented Nov 1, 2020

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.

@johnthagen
Copy link
Owner

See if #44 helps at all.

@firewave
Copy link
Collaborator Author

firewave commented Nov 1, 2020

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.

@johnthagen
Copy link
Owner

For what it's worth, I am using 2020.2.3 currently successfully.

@johnthagen
Copy link
Owner

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

cppcheck-gutter

@johnthagen
Copy link
Owner

Closing as invalid as this appears to be normal behavior for IntelliJ-based tools.

@firewave
Copy link
Collaborator Author

firewave commented Nov 1, 2020

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.

@johnthagen johnthagen reopened this Nov 1, 2020
@firewave
Copy link
Collaborator Author

firewave commented Nov 2, 2020

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.

@firewave
Copy link
Collaborator Author

firewave commented Nov 2, 2020

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. :)

@firewave firewave removed their assignment Nov 21, 2020
@firewave firewave added the bug label Dec 23, 2020
@firewave
Copy link
Collaborator Author

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 &apos;s6&apos; is assigned a value that is never used." verbose="Variable &apos;s6&apos; 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>

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants