Closed
Bug 1126813
Opened 11 years ago
Closed 10 years ago
analysis to detect for (auto i : container) and suggest something more suitable
Categories
(Developer Infrastructure :: Source Code Analysis, defect)
Developer Infrastructure
Source Code Analysis
Tracking
(firefox43 fixed)
RESOLVED
FIXED
mozilla43
| Tracking | Status | |
|---|---|---|
| firefox43 | --- | fixed |
People
(Reporter: froydnj, Assigned: ehsan.akhgari)
References
Details
Attachments
(1 file)
|
5.30 KB,
patch
|
gps
:
review+
|
Details | Diff | Splinter Review |
Range-based for loops are very convenient, but the easy way to write them:
for (auto i : container) { ... }
will invoke copy-constructors unnecessarily. That's almost always not what we want. We should have a static analysis that figures out if we'd be invoking (non-trivial?) copy constructors in range-based for loops and disallows them, requiring:
for (auto& i : container) { ... }
instead. I know bent prefers (and maybe enforces in reviews?) |auto&| or |auto*| to make reference/pointer-ness explicit. Maybe we should adopt that for the style guide...?
Some future version of Clang will contain a warning for this: http://reviews.llvm.org/rL234804
| Assignee | ||
Comment 2•10 years ago
|
||
Should we just turn on -Werror=range-loop-analysis?
Flags: needinfo?(nfroyd)
| Reporter | ||
Comment 4•10 years ago
|
||
(In reply to Ehsan Akhgari (don't ask for review please) from comment #2)
> Should we just turn on -Werror=range-loop-analysis?
Assuming I understand the comments in the commit (hooray for non-existent documentation), I think this is what we want.
Flags: needinfo?(nfroyd)
| Assignee | ||
Updated•10 years ago
|
Flags: needinfo?(ehsan)
| Assignee | ||
Comment 5•10 years ago
|
||
Attachment #8657439 -
Flags: review?(gps)
| Assignee | ||
Comment 6•10 years ago
|
||
Flags: needinfo?(ehsan)
Comment 7•10 years ago
|
||
Comment on attachment 8657439 [details] [diff] [review]
Turn on the -Wrange-loop-analysis warning if available
Review of attachment 8657439 [details] [diff] [review]:
-----------------------------------------------------------------
Unrelated to this change, it looks like we have some duplication of code between the 2 configures. Since this code is related to code sanity and since I believe Gecko and SpiderMonkey share a unified convention now, we may want to follow-up by consolidating this code into a standalone m4 file.
Attachment #8657439 -
Flags: review?(gps) → review+
| Assignee | ||
Comment 8•10 years ago
|
||
The warning flags are quite different, so I don't think that would result in any code sharing.
Comment 10•10 years ago
|
||
Assignee: nobody → ehsan
Status: NEW → RESOLVED
Closed: 10 years ago
status-firefox43:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla43
Updated•7 years ago
|
Product: Core → Firefox Build System
Updated•3 years ago
|
Product: Firefox Build System → Developer Infrastructure
You need to log in
before you can comment on or make changes to this bug.
Description
•