Closed Bug 1684092 Opened 1 year ago Closed 10 months ago

Replace MOZ_MUST_USE with [[nodiscard]] in js/src/

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

RESOLVED FIXED
87 Branch
Tracking Status
firefox-esr78 --- wontfix
firefox84 --- wontfix
firefox85 --- wontfix
firefox86 --- wontfix
firefox87 --- fixed

People

(Reporter: cpeterson, Assigned: cpeterson)

References

Details

Attachments

(3 files, 1 obsolete file)

The MOZ_MUST_USE macro is defined as clang's and gcc's nonstandard __attribute__((warn_unused_result)). Now that we compile as C++17 by default (bug 1560664), we can replace MOZ_MUST_USE with C++17's standard [[nodiscard]] attribute.

The [[nodiscard]] attribute must precede a function declaration's declaration specifiers (like static, extern, inline, or virtual). The __attribute__((warn_unused_result)) attribute does not have this order restriction.

See Also: → 1684089
See Also: → 1684091

The MOZ_MUST_USE macro is defined as clang's and gcc's nonstandard attribute((warn_unused_result)). Now that we compile as C++17 by default (bug 1560664), we can replace MOZ_MUST_USE with C++17's standard [[nodiscard]] attribute.

The [[nodiscard]] attribute must precede a function declaration's declaration specifiers (like static, extern, inline, or virtual). The attribute((warn_unused_result)) attribute does not have this order restriction.

Depends on D100412

We don't need to #include Attributes.h now that we're using [[nodiscard]] instead of MOZ_MUST_USE.

Depends on D100413

V8_WARN_UNUSED_RESULT can't use [[nodiscard]] because [[nodiscard]] has more restrictions on function declaration specifiers than attribute((warn_unused_result)). The affected code is third-party code from V8's irregexp, so instead of changing upstream code, revert V8_WARN_UNUSED_RESULT to its upstream definition using attribute((warn_unused_result)).

Depends on D100414

Comment on attachment 9194590 [details]
Bug 1684092 - Part 4: Revert V8_WARN_UNUSED_RESULT to upstream definition using attribute((warn_unused_result)). r?jorendorff

Part 4 was obsoleted by bug 1688350 comment 1

Attachment #9194590 - Attachment is obsolete: true

I rebased these s/MOZ_MUST_USE/[[nodiscard]]/ find-and-replace patches. They bit rot quickly because they touch a lot of header files.

Attachment #9194590 - Attachment is obsolete: false
Attachment #9194590 - Attachment is obsolete: true
Attachment #9194584 - Attachment description: Bug 1684092 - Part 1: Replace MOZ_MUST_USE with [[nodiscard]] in js/src/. r?jorendorff → Bug 1684092 - Part 1: Replace MOZ_MUST_USE with [[nodiscard]] in js/src/. r?jandem
Attachment #9194585 - Attachment description: Bug 1684092 - Part 2: Move [[nodiscard]] to the head of function declarations in js/src/. r?jorendorff → Bug 1684092 - Part 2: Move [[nodiscard]] to the head of function declarations in js/src/. r?jandem
Attachment #9194588 - Attachment description: Bug 1684092 - Part 3: Remove unnecessary #includes of Attributes.h for MOZ_MUST_USE in js/src/. r?jorendorff → Bug 1684092 - Part 3: Remove unnecessary #includes of Attributes.h for MOZ_MUST_USE in js/src/. r?jandem
Pushed by cpeterson@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/bfaa95b5e04a
Part 1: Replace MOZ_MUST_USE with [[nodiscard]] in js/src/. r=jandem
https://hg.mozilla.org/integration/autoland/rev/331046f56c01
Part 2: Move [[nodiscard]] to the head of function declarations in js/src/. r=jandem
https://hg.mozilla.org/integration/autoland/rev/1f385759e3f5
Part 3: Remove unnecessary #includes of Attributes.h for MOZ_MUST_USE in js/src/. r=jandem
Status: NEW → RESOLVED
Closed: 10 months ago
Resolution: --- → FIXED
Target Milestone: --- → 87 Branch
You need to log in before you can comment on or make changes to this bug.