-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix #13148 FN: constStatement (static_cast<void>(integer|nullptr|NULL)) #8694
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,9 @@ void f() | |
| { | ||
| #if DEF_1 | ||
| // cppcheck-suppress id | ||
| (void)0; | ||
| ; | ||
| #endif | ||
|
|
||
| // cppcheck-suppress id | ||
| (void)0; | ||
| ; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,9 +180,25 @@ class TestIncompleteStatement : public TestFixture { | |
| } | ||
|
|
||
| void void0() { // #6327 | ||
| check("void f() { (void*)0; }"); | ||
| check("#define assert(x) ((void)0)\n" | ||
| "void f(int* p) {\n" | ||
| " assert(p);\n" | ||
| "}\n"); | ||
| ASSERT_EQUALS("", errout_str()); | ||
|
|
||
| check("void f() { (void*)0; }"); | ||
| ASSERT_EQUALS("[test.cpp:1:12]: (warning) Redundant code: Found a statement that begins with numeric constant. [constStatement]\n", errout_str()); | ||
|
|
||
| check("void f() {\n" // #13148 | ||
| " static_cast<void>(1);\n" | ||
| " static_cast<void>(nullptr);\n" | ||
| " (void)NULL;\n" | ||
| "}\n"); | ||
| ASSERT_EQUALS("[test.cpp:2:22]: (warning) Redundant code: Found a statement that begins with numeric constant. [constStatement]\n" | ||
| "[test.cpp:3:22]: (warning) Redundant code: Found a statement that begins with NULL constant. [constStatement]\n" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally we would not say that nullptr ist a NULL constant. can we write |
||
| "[test.cpp:4:5]: (warning) Redundant code: Found a statement that begins with NULL constant. [constStatement]\n", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this test case it just looks like a redundant statement , I wonder if the severity should be "style" instead. Are there bugs discovered by this checker or just code cleanup? We could change the severity in a separate PR. |
||
| errout_str()); | ||
|
|
||
| check("#define X 0\n" | ||
| "void f() { X; }"); | ||
| ASSERT_EQUALS("", errout_str()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm.. the warning message is not technically correct. I would say that the cast comes before the numeric constant.
maybe we should try to reformulate this somehow.