Closed Bug 2062227 Opened 3 months ago Closed 3 months ago

Make mozilla::detail::ComputeGrowth inline instead of static to fix -Wunused-template with clang 23

Categories

(Core :: MFBT, defect)

defect

Tracking

()

RESOLVED FIXED
155 Branch
Tracking Status
firefox-esr115 --- wontfix
firefox-esr140 --- wontfix
firefox-esr153 --- wontfix
firefox153 --- wontfix
firefox154 --- wontfix
firefox155 --- fixed

People

(Reporter: Sylvestre, Assigned: Sylvestre)

References

(Blocks 2 open bugs, Regression)

Details

(Keywords: regression)

Attachments

(1 external file)

Building with clang 23 fails in any TU that includes mfbt/Vector.h:

In file included from obj-x86_64-pc-linux-gnu/memory/replace/dmd/Unified_cpp_memory_replace_dmd0.cpp:2:
In file included from memory/replace/dmd/DMD.cpp:38:
In file included from mfbt/JSONWriter.h:100:
mfbt/Vector.h:131:15: error: unused function template 'ComputeGrowth' [-Werror,-Wunused-template]
  131 | static size_t ComputeGrowth(
      |               ^~~~~~~~~~~~~

mozilla::detail::ComputeGrowth is a SFINAE overload pair: one version forwards
to the AllocPolicy's own computeGrowth<EltSize>() when it has one, the other
falls back to GrowEltsByDoubling(). Any given translation unit selects exactly
one of the two, so the other is necessarily unused. Because both are declared
static, that unused one is an internal-linkage template with no
instantiations, which is precisely what -Wunused-template reports.

The fix is to declare them inline rather than static, matching
GrowEltsByDoubling() directly above them:

-static size_t ComputeGrowth(size_t aOldElts, size_t aIncr, int) {
+inline size_t ComputeGrowth(size_t aOldElts, size_t aIncr, int) {

-static size_t ComputeGrowth(
+inline size_t ComputeGrowth(

-Wunused-template only applies to internal-linkage templates, so this removes
the warning at its source instead of suppressing it. The definitions are
identical in every translation unit, so external linkage raises no ODR concern,
and the only caller is Vector.h:1094 within mozilla::detail

Type: task → defect
Keywords: regression
Regressed by: 1774733
Assignee: nobody → sledru
Status: NEW → ASSIGNED
Attachment #9624711 - Attachment description: Bug 2062227 - Make mozilla::detail::ComputeGrowth inline instead of static to fix -Wunused-template with clang 23 r?sfink → Bug 2062227 - Remove static from mozilla::detail::ComputeGrowth to fix -Wunused-template with clang 23 r?sfink
Pushed by sledru@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/ab8defc34da0 https://hg.mozilla.org/integration/autoland/rev/39f000e410ed Remove static from mozilla::detail::ComputeGrowth to fix -Wunused-template with clang 23 r=sergesanspaille
Status: ASSIGNED → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 155 Branch

Set release status flags based on info from the regressing bug 1774733

QA Whiteboard: [qa-triage-done-c156/b155]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: