Enable clang's -Wstring-conversion warnings

RESOLVED FIXED in Firefox 50

Status

RESOLVED FIXED
3 years ago
10 months ago

People

(Reporter: cpeterson, Assigned: cpeterson)

Tracking

(Blocks: 1 bug)

unspecified
mozilla50
Dependency tree / graph

Firefox Tracking Flags

(firefox48 wontfix, firefox49 affected, firefox50 fixed)

Details

Attachments

(1 attachment)

(Assignee)

Description

3 years ago
Created attachment 8758985 [details] [diff] [review]
enable-Wstring-conversion.patch

clang's -Wstring-conversion warns about implicit conversion of string literals into bools. String literals are sometimes used like this for "always fail" assertions like assert(!"always fails"). "Always fail" assertions are better expressed using MOZ_ASSERT_UNREACHABLE() or MOZ_CRASH() with a reason string.

In any other case, this usage is usually a bug. For example:

* In bug 1276567, a function with return type bool returned a string literal "<dead CPOW>" without a compiler error or warning because the string literal was implicitly converted to true.

* In bug 980810 and bug 1277009, some assertions with string literal arguments forgot the ! so the assertions were always true no-ops instead of always false aborts. That mistake would not be possible using MOZ_ASSERT_UNREACHABLE() or MOZ_CRASH().

Green Try build with -Wstring-conversion warnings enabled:
https://treeherder.mozilla.org/#/jobs?repo=try&revision=f26518fc2522
Attachment #8758985 - Flags: review?(mh+mozilla)
Attachment #8758985 - Flags: review?(mh+mozilla) → review+

Comment 1

3 years ago
Pushed by cpeterson@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/2863cfa9daf1
Enable clang's -Wstring-conversion warnings. r=glandium

Comment 2

3 years ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/2863cfa9daf1
Status: NEW → RESOLVED
Last Resolved: 3 years ago
status-firefox50: --- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla50

Updated

10 months ago
Product: Core → Firefox Build System
You need to log in before you can comment on or make changes to this bug.