-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
two new compiler error explanations added
- Loading branch information
1 parent
49b72b8
commit 9b754d9
Showing
16 changed files
with
152 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
If you forget a curly bracket, e.g. | ||
```c | ||
int sum(int x, int y) { | ||
if (x > y) { | ||
return x + y; | ||
} else { | ||
return x - y; | ||
// <-- missing closing curly bracket | ||
} | ||
|
||
int f(int x) { | ||
return sum(x, x); | ||
} | ||
``` | ||
The compiler will give an error when the next function definition starts. | ||
You can fix by adding the missing curly bracket (brace): | ||
```c | ||
int sum(int x, int y) { | ||
if (x > y) { | ||
return x + y; | ||
} else { | ||
return x - y; | ||
} | ||
} | ||
int f(int x) { | ||
return sum(x, x); | ||
} | ||
``` |
File renamed without changes.
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
6 changes: 6 additions & 0 deletions
6
tests/expected_output/clang-6.0-x86_64-pc-linux-gnu/function-definition-not-allowed-here.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,6 @@ | ||
tests/extracted_compile_time_tests/function-definition-not-allowed-here.c:5:16: error: function definition is not allowed here | ||
int main(void) { | ||
^ | ||
dcc explanation: There is likely a closing brace (curly bracket) missing before line 5. | ||
Is a } missing in the previous function? | ||
See more information here: https://comp1511unsw.github.io/dcc/function-definition-not-allowed-here.html |
7 changes: 7 additions & 0 deletions
7
tests/expected_output/clang-6.0-x86_64-pc-linux-gnu/function-variable-clash.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,7 @@ | ||
tests/extracted_compile_time_tests/function-variable-clash.c:4:13: error: called object type 'int' is not a function or function pointer | ||
return main(); | ||
~~~~^ | ||
dcc explanation: 'main' is the name of a variable but you are trying to call it as a function. | ||
If 'main' is also the name of a function, you can avoid the clash, | ||
by changing the name of the variable 'main' to something else. | ||
See more information here: https://comp1511unsw.github.io/dcc/function-variable-clash.html |
6 changes: 6 additions & 0 deletions
6
tests/expected_output/clang-6.0-x86_64-pc-linux-gnu/indirection-requires-pointer-operand.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,6 @@ | ||
tests/extracted_compile_time_tests/indirection-requires-pointer-operand.c:3:9: error: indirection requires pointer operand ('int' invalid) | ||
return *argc; | ||
^~~~~ | ||
dcc explanation: you are trying to use 'argc' as a pointer. | ||
You can not do this because 'argc' is of type int. | ||
|
6 changes: 6 additions & 0 deletions
6
tests/expected_output/clang-6.0-x86_64-pc-linux-gnu/uninitialized-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,6 @@ | ||
tests/extracted_compile_time_tests/uninitialized-local-variable.c: In function ‘main’: | ||
tests/extracted_compile_time_tests/uninitialized-local-variable.c:4:10: warning: ‘a[0]’ is used uninitialized in this function [-Wuninitialized] | ||
return a[0]; | ||
~^~~[0m | ||
dcc explanation: You are using the value of the variable a[0] before assigning a value to a[0]. | ||
|
6 changes: 6 additions & 0 deletions
6
tests/expected_output/clang-7.0-x86_64-pc-linux-gnu/function-definition-not-allowed-here.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,6 @@ | ||
tests/extracted_compile_time_tests/function-definition-not-allowed-here.c:5:16: error: function definition is not allowed here | ||
int main(void) { | ||
^ | ||
dcc explanation: There is likely a closing brace (curly bracket) missing before line 5. | ||
Is a } missing in the previous function? | ||
See more information here: https://comp1511unsw.github.io/dcc/function-definition-not-allowed-here.html |
7 changes: 7 additions & 0 deletions
7
tests/expected_output/clang-7.0-x86_64-pc-linux-gnu/function-variable-clash.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,7 @@ | ||
tests/extracted_compile_time_tests/function-variable-clash.c:4:13: error: called object type 'int' is not a function or function pointer | ||
return main(); | ||
~~~~^ | ||
dcc explanation: 'main' is the name of a variable but you are trying to call it as a function. | ||
If 'main' is also the name of a function, you can avoid the clash, | ||
by changing the name of the variable 'main' to something else. | ||
See more information here: https://comp1511unsw.github.io/dcc/function-variable-clash.html |
6 changes: 6 additions & 0 deletions
6
tests/expected_output/clang-7.0-x86_64-pc-linux-gnu/indirection-requires-pointer-operand.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,6 @@ | ||
tests/extracted_compile_time_tests/indirection-requires-pointer-operand.c:3:9: error: indirection requires pointer operand ('int' invalid) | ||
return *argc; | ||
^~~~~ | ||
dcc explanation: you are trying to use 'argc' as a pointer. | ||
You can not do this because 'argc' is of type int. | ||
|
6 changes: 6 additions & 0 deletions
6
tests/expected_output/clang-7.0-x86_64-pc-linux-gnu/uninitialized-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,6 @@ | ||
tests/extracted_compile_time_tests/uninitialized-local-variable.c: In function ‘main’: | ||
tests/extracted_compile_time_tests/uninitialized-local-variable.c:4:10: warning: ‘a[0]’ is used uninitialized in this function [-Wuninitialized] | ||
return a[0]; | ||
~^~~[0m | ||
dcc explanation: You are using the value of the variable a[0] before assigning a value to a[0]. | ||
|
6 changes: 6 additions & 0 deletions
6
tests/expected_output/clang-8.0-x86_64-pc-linux-gnu/function-definition-not-allowed-here.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,6 @@ | ||
tests/extracted_compile_time_tests/function-definition-not-allowed-here.c:5:16: error: function definition is not allowed here | ||
int main(void) { | ||
^ | ||
dcc explanation: There is likely a closing brace (curly bracket) missing before line 5. | ||
Is a } missing in the previous function? | ||
See more information here: https://comp1511unsw.github.io/dcc/function-definition-not-allowed-here.html |
7 changes: 7 additions & 0 deletions
7
tests/expected_output/clang-8.0-x86_64-pc-linux-gnu/function-variable-clash.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,7 @@ | ||
tests/extracted_compile_time_tests/function-variable-clash.c:4:13: error: called object type 'int' is not a function or function pointer | ||
return main(); | ||
~~~~^ | ||
dcc explanation: 'main' is the name of a variable but you are trying to call it as a function. | ||
If 'main' is also the name of a function, you can avoid the clash, | ||
by changing the name of the variable 'main' to something else. | ||
See more information here: https://comp1511unsw.github.io/dcc/function-variable-clash.html |
6 changes: 6 additions & 0 deletions
6
tests/expected_output/clang-8.0-x86_64-pc-linux-gnu/indirection-requires-pointer-operand.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,6 @@ | ||
tests/extracted_compile_time_tests/indirection-requires-pointer-operand.c:3:9: error: indirection requires pointer operand ('int' invalid) | ||
return *argc; | ||
^~~~~ | ||
dcc explanation: you are trying to use 'argc' as a pointer. | ||
You can not do this because 'argc' is of type int. | ||
|
6 changes: 6 additions & 0 deletions
6
tests/expected_output/clang-8.0-x86_64-pc-linux-gnu/uninitialized-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,6 @@ | ||
tests/extracted_compile_time_tests/uninitialized-local-variable.c: In function ‘main’: | ||
tests/extracted_compile_time_tests/uninitialized-local-variable.c:4:10: warning: ‘a[0]’ is used uninitialized in this function [-Wuninitialized] | ||
return a[0]; | ||
~^~~[0m | ||
dcc explanation: You are using the value of the variable a[0] before assigning a value to a[0]. | ||
|