https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123293
Bug ID: 123293
Summary: go: add an option to ignore "imported and not used"
and "declared but not used" errors
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: go
Assignee: ian at airs dot com
Reporter: bruno at clisp dot org
Target Milestone: ---
Created attachment 63150
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63150&action=edit
sample code during development
It would be helpful to have a compiler option that turns the following types of
errors into mere warnings (or silences them entirely):
error: imported and not used: <package>
error: ‘<variable>’ declared but not used
I have not seen such an option documented in
https://gcc.gnu.org/onlinedocs/gcc-15.2.0/gccgo/Invoking-gccgo.html .
Rationale:
I am an experienced developer, and when I write code, I typically do:
1. write about 50 lines of code, without compiling or testig anything.
2. Comment out most of the new code.
3. Uncomment 2 or 3 lines. Compile and test these lines.
4. Uncomment 2 or 3 more lines. Compile and test these lines.
5. Uncomment 2 or 3 more lines. Compile and test these lines.
...
The problem is that this produces a couple of errors of the form described
above.
It forces me to
- comment out some of the imports, that I will uncomment just a minute later,
- add statements like '_ := <variable>', that I will remove just two minutes
later.
In other words, these errors make _developing_ Go code painful, and part of
this time is wasted doing changes that are just to be present for a few
seconds. If these errors were merely warnings, there would be no problem.
Example:
$ gccgo -Wall -O2 -o ollama-spit ollama-spit.go
ollama-spit.go:23:16: error: imported and not used: context
23 | "context"
| ^
ollama-spit.go:27:12: error: imported and not used: log
27 | "log"
| ^
ollama-spit.go:28:17: error: imported and not used: http
28 | "net/http"
| ^
ollama-spit.go:81:9: error: ‘model’ declared but not used
81 | model := *model_option
| ^
ollama-spit.go:84:9: error: ‘allBytes’ declared but not used
84 | allBytes, err := io.ReadAll(os.Stdin)
| ^