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

syntaxError in include is hidden - leading to suspected false negative #74

Open
firewave opened this issue Mar 9, 2022 · 4 comments
Open
Assignees

Comments

@firewave
Copy link
Collaborator

firewave commented Mar 9, 2022

test.h

enum Type
{
	ERROR
};

struct A
{
};

test.cpp

#include "test.h"

extern void f()
{
    A a; // unusedVariable
}

In Cppcheck 2.4 the header will generate a syntaxError with the Windows version:

test.h:1:1: error: syntax error [syntaxError]
enum Type
^

This leads to the unusedVariable in function f() not being reported making it seems like a false negative since the syntaxError is being suppressed as it didn't occur in the file we are analyzing.

We need to make this error visible - possibly via a global warning about this.

There's most likely other errors which may lead to the same problem.

@firewave firewave self-assigned this Mar 9, 2022
@johnthagen
Copy link
Owner

I wonder if there is a hook to simply not run if there are syntax errors. I know that is how many people set up File Watchers in IntelliJ products.

@firewave
Copy link
Collaborator Author

firewave commented Mar 9, 2022

This syntax error is a bug in Cppcheck. Also Cppcheck is built to being able to handle incomplete and invalid code.

There's also cases where it could be caused by a simple misconfiguration.

I came across this while working on code and trying to figure out the "false negative" of a unused variable not being reported which turned out to be this issue in the header.

I already know how to fix it but I want to get #60 in before since it simplifies things.

@firewave
Copy link
Collaborator Author

A preview of the fix I am currently testing:

image

I am not sure if you can put links in such in messages. Being able to directly jump to the file/line in question would be awesome.

@firewave firewave changed the title syntaxError in include is hidden leading to suspected false negative syntaxError in include is hidden - leading to suspected false negative Mar 14, 2022
@firewave
Copy link
Collaborator Author

firewave commented Sep 4, 2023

Note: A potential fix for https://trac.cppcheck.net/ticket/11913 might affect this.

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

No branches or pull requests

2 participants