-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add gcc optional warnings for duplicated-branches duplicated-cond log…
…ical-op with explanations
- Loading branch information
1 parent
45a94ae
commit e2cc9a2
Showing
26 changed files
with
404 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/expected_output/clang-6.0-x86_64-pc-linux-gnu/duplicated-branches.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
tests/extracted_compile_time_errors/duplicated-branches.c: In function ‘main’: | ||
tests/extracted_compile_time_errors/duplicated-branches.c:3:5: warning: this condition has identical branches [-Wduplicated-branches] | ||
if (argc == 1) | ||
^ | ||
dcc explanation: Your if statement has identical then and else parts. | ||
It is pointless to have an if statement which executes the same code | ||
when the condition is true and when it is false. | ||
|
||
|
||
|
13 changes: 13 additions & 0 deletions
13
tests/expected_output/clang-6.0-x86_64-pc-linux-gnu/duplicated-cond.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
tests/extracted_compile_time_errors/duplicated-cond.c: In function ‘main’: | ||
tests/extracted_compile_time_errors/duplicated-cond.c:5:16: warning: duplicated ‘if’ condition [-Wduplicated-cond] | ||
else if (argc == 1) | ||
~~~~~^~~~ | ||
tests/extracted_compile_time_errors/duplicated-cond.c:3:11: note: previously used here | ||
if (argc == 1) | ||
~~~~~^~~~[0m | ||
dcc explanation: You have repeated the same condition in a chain of if statements. | ||
Only the first if statement using the condition can be executed. | ||
The others can never be executed. | ||
|
||
|
||
|
9 changes: 9 additions & 0 deletions
9
tests/expected_output/clang-6.0-x86_64-pc-linux-gnu/logical-and-always-false.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
tests/extracted_compile_time_errors/logical-and-always-false.c: In function ‘main’: | ||
tests/extracted_compile_time_errors/logical-and-always-false.c:3:15: warning: logical ‘and’ of mutually exclusive tests is always false [-Wlogical-op] | ||
if (argc > 1 && argc < 1) | ||
^~[0m | ||
dcc explanation: Your '&&' expression is always false, no matter what value variables have. | ||
Perhaps you meant to use '||' ? | ||
|
||
|
||
|
9 changes: 9 additions & 0 deletions
9
tests/expected_output/clang-6.0-x86_64-pc-linux-gnu/logical-equal-expressions.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
tests/extracted_compile_time_errors/logical-equal-expressions.c: In function ‘main’: | ||
tests/extracted_compile_time_errors/logical-equal-expressions.c:3:15: warning: logical ‘or’ of equal expressions [-Wlogical-op] | ||
if (argc > 1 ||argc > 1) | ||
^~[0m | ||
dcc explanation: Your have used '||' with same lefthand and righthand operands. | ||
If this what you meant, it can be simplified: x || x can be replaced with just x. | ||
|
||
|
||
|
9 changes: 9 additions & 0 deletions
9
tests/expected_output/clang-6.0-x86_64-pc-linux-gnu/logical-or-always-true.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
tests/extracted_compile_time_errors/logical-or-always-true.c: In function ‘main’: | ||
tests/extracted_compile_time_errors/logical-or-always-true.c:3:15: warning: logical ‘or’ of collectively exhaustive tests is always true [-Wlogical-op] | ||
if (argc > 1 || argc < 3) | ||
^~[0m | ||
dcc explanation: Your '||' expression is always true, no matter what value variables have. | ||
Perhaps you meant to use '&&' ? | ||
|
||
|
||
|
11 changes: 11 additions & 0 deletions
11
tests/expected_output/clang-6.0-x86_64-pc-linux-gnu/shadow-local-variable.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
tests/extracted_compile_time_errors/shadow-local-variable.c:4:7: warning: declaration shadows a local variable [-Wshadow] | ||
int argc = 42; | ||
^ | ||
tests/extracted_compile_time_errors/shadow-local-variable.c:2:14: note: previous declaration is here | ||
int main(int argc, char *argv[]) { | ||
^[0m | ||
dcc explanation: Your already have a variable named 'argc'. | ||
It is confusing to have a second overlapping declaration of the same variable name. | ||
|
||
|
||
|
10 changes: 10 additions & 0 deletions
10
tests/expected_output/clang-7.0-x86_64-pc-linux-gnu/duplicated-branches.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
tests/extracted_compile_time_errors/duplicated-branches.c: In function ‘main’: | ||
tests/extracted_compile_time_errors/duplicated-branches.c:3:5: warning: this condition has identical branches [-Wduplicated-branches] | ||
if (argc == 1) | ||
^ | ||
dcc explanation: Your if statement has identical then and else parts. | ||
It is pointless to have an if statement which executes the same code | ||
when the condition is true and when it is false. | ||
|
||
|
||
|
13 changes: 13 additions & 0 deletions
13
tests/expected_output/clang-7.0-x86_64-pc-linux-gnu/duplicated-cond.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
tests/extracted_compile_time_errors/duplicated-cond.c: In function ‘main’: | ||
tests/extracted_compile_time_errors/duplicated-cond.c:5:16: warning: duplicated ‘if’ condition [-Wduplicated-cond] | ||
else if (argc == 1) | ||
~~~~~^~~~ | ||
tests/extracted_compile_time_errors/duplicated-cond.c:3:11: note: previously used here | ||
if (argc == 1) | ||
~~~~~^~~~[0m | ||
dcc explanation: You have repeated the same condition in a chain of if statements. | ||
Only the first if statement using the condition can be executed. | ||
The others can never be executed. | ||
|
||
|
||
|
Oops, something went wrong.