4 ms·
Won't the compiler just ignore the "builder.String()" line unless the return value is actually used?
by marcus_holmes 9y ago
Won't the compiler just ignore the "builder.String()" line unless the return value is actually used?
- zaarn 9y agoEasy fix, use the anonymous variable; _ = builder.String() The compiler should not optimize that out.
- majewsky 9y agoThat's absolutely the same as the statement without assignment from a data flow POV. However, the compiler will likely not optimize it away since it would be too burdensome to proof that strings.Builder.String() does not have any side effects. The Go compiler prides itself with fast compilation speed, so I would not expect it to perform cross-package control/data flow analyses.