Closed Bug 1483761 Opened 6 years ago Closed 6 years ago

Enable some more clang warnings: -Wc++2a-compat, -Wfloat-(overflow|zero)-conversion, -Wtautological-overlap-compare

Categories

(Developer Infrastructure :: Source Code Analysis, enhancement, P3)

enhancement

Tracking

(firefox-esr52 wontfix, firefox-esr60 wontfix, firefox61 wontfix, firefox62 wontfix, firefox63 fixed)

RESOLVED FIXED
mozilla63
Tracking Status
firefox-esr52 --- wontfix
firefox-esr60 --- wontfix
firefox61 --- wontfix
firefox62 --- wontfix
firefox63 --- fixed

People

(Reporter: cpeterson, Assigned: cpeterson)

References

(Blocks 1 open bug)

Details

Attachments

(4 files, 1 obsolete file)

-Wfloat-overflow-conversion detects when a constant floating point value is converted to an integer type and will overflow the target type. https://clang.llvm.org/docs/DiagnosticsReference.html#wfloat-overflow-conversion -Wfloat-zero-conversion detects when a non-zero floating point value is converted to a zero integer value. https://clang.llvm.org/docs/DiagnosticsReference.html#wfloat-zero-conversion There are currently no -Wfloat-overlap-conversion warnings in mozilla-central. There is one -Wfloat-zero-conversion warning in a webrtc test. It doesn't block enabling this check because the webrtc tests are not compiled with warnings-as-errors. media/webrtc/trunk/webrtc/modules/audio_coding/audio_network_adaptor/frame_length_controller_unittest.cc:255:54 [-Wfloat-zero-conversion] implicit conversion from 'const float' to 'int' changes non-zero value from 0.045000002 to 0 We can't enable all -Wfloat-conversion warnings (for any implicit conversion of a floating-point number into an integer) because there are currently over 1400 warnings. I spot checked a few of these -Wfloat-conversion warnings. I didn't find any obvious bugs, but there is some suspicious code, such as implicit conversions of floats to bools.
-Wtautological-overlap-compare is an opt-in warning added in clang 3.5. It warns about overlapping comparisons that are always true or false, such as: if (x > 4 || x < 10) {} // warning! always true int b = x < 2 && x > 5; // warning! always false return x > 4 || x < 10; // warning! always true https://clang.llvm.org/docs/DiagnosticsReference.html#wtautological-overlap-compare There are currently no -Wtautological-overlap-compare warnings in mozilla-central. Depends on D3476
Warn about C++ constructs whose meaning change in C++2a. https://clang.llvm.org/docs/DiagnosticsReference.html#wc-2a-compat So far the only -Wc++2a-compat check that I know of is for valid pre-C++2a code that inadvertently parses as C++2a's new <=> "spaceship" comparison operator. `f<&A::operator<=>();` is an example of a warning reported for a real project on GitHub. That code can be rewritten as `f< &operator<= >();`. There are currently no -Wc++2a-compat warnings in mozilla-central. Depends on D3477
This opt-in warning catches bugs where a constructor modifies a constructor parameter that shadows member variable name. The code probably intended to change the member variable value, not the paramter. There are currently no -Wshadow-field-in-constructor warnings in mozilla-central. https://clang.llvm.org/docs/DiagnosticsReference.html#wshadow-field-in-constructor-modified Depends on D3478
Comment on attachment 9001511 [details] Bug 1483761 - Enable clang's -Wfloat-(overflow|zero)-conversion warnings. r=glandium Mike Hommey [:glandium] has approved the revision.
Attachment #9001511 - Flags: review+
Comment on attachment 9001512 [details] Bug 1483761 - Enable clang's -Wtautological-overlap-compare warning. r=glandium Mike Hommey [:glandium] has approved the revision.
Attachment #9001512 - Flags: review+
Comment on attachment 9001513 [details] Bug 1483761 - Enable clang's -Wc++2a-compat warnings. r=glandium Mike Hommey [:glandium] has approved the revision.
Attachment #9001513 - Flags: review+
Comment on attachment 9002573 [details] Bug 1483761 - Enable clang's -Wshadow-field-in-constructor warnings. r=glandium Mike Hommey [:glandium] has approved the revision.
Attachment #9002573 - Flags: review+
Pushed by cpeterson@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/f9a890fba236 Enable clang's -Wc++2a-compat warnings. r=glandium https://hg.mozilla.org/integration/mozilla-inbound/rev/36f6bab3d669 Enable clang's -Wfloat-(overflow|zero)-conversion warnings. r=glandium https://hg.mozilla.org/integration/mozilla-inbound/rev/f41a14a1b4de Enable clang's -Wshadow-field-in-constructor warnings. r=glandium https://hg.mozilla.org/integration/mozilla-inbound/rev/6d30bac7078b Enable clang's -Wtautological-overlap-compare warning. r=glandium
Depends on: 1509926

-Wfloat-overflow-conversion detects when a constant floating point value is converted to an integer type and will overflow the target type.

https://clang.llvm.org/docs/DiagnosticsReference.html#wfloat-overflow-conversion

-Wfloat-zero-conversion detects when a non-zero floating point value is converted to a zero integer value.

https://clang.llvm.org/docs/DiagnosticsReference.html#wfloat-zero-conversion

There are currently no -Wfloat-overlap-conversion warnings in mozilla-central. There is one -Wfloat-zero-conversion warning in a webrtc test. It doesn't block enabling this check because the webrtc tests are not compiled with warnings-as-errors.

media/webrtc/trunk/webrtc/modules/audio_coding/audio_network_adaptor/frame_length_controller_unittest.cc:255:54 [-Wfloat-zero-conversion] implicit conversion from 'const float' to 'int' changes non-zero value from 0.045000002 to 0

We can't enable all -Wfloat-conversion warnings (for any implicit conversion of a floating-point number into an integer) because there are currently over 1400 warnings. I spot checked a few of these -Wfloat-conversion warnings. I didn't find any obvious bugs, but there is some suspicious code, such as implicit conversions of floats to bools.

Bug 1483761 - Enable clang's -Wtautological-overlap-compare warning. r?glandium

-Wtautological-overlap-compare is an opt-in warning added in clang 3.5. It warns about overlapping comparisons that are always true or false, such as:

if (x > 4 || x < 10) {} // warning! always true
int b = x < 2 && x > 5; // warning! always false
return x > 4 || x < 10; // warning! always true

https://clang.llvm.org/docs/DiagnosticsReference.html#wtautological-overlap-compare

There are currently no -Wtautological-overlap-compare warnings in mozilla-central.

Bug 1483761 - Enable clang's -Wc++2a-compat warnings. r?glandium

Warn about C++ constructs whose meaning change in C++2a.

https://clang.llvm.org/docs/DiagnosticsReference.html#wc-2a-compat

So far the only -Wc++2a-compat check that I know of is for valid pre-C++2a code that inadvertently parses as C++2a's new <=> "spaceship" comparison operator. f<&A::operator<=>(); is an example of a warning reported for a real project on GitHub. That code can be rewritten as f< &operator<= >();.

There are currently no -Wc++2a-compat warnings in mozilla-central.

Attachment #9050532 - Attachment is obsolete: true

Closing this old Phabricator revision because it was already reviewed and landed (in comment 10 above).

See Also: → 1718408
Blocks: C++20
Product: Firefox Build System → Developer Infrastructure
Depends on: 1880917
Blocks: 1880917
No longer depends on: 1880917
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: