with -std=gnu++17, build fails with NumberFormat.cpp:443:25: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
Categories
(Core :: JavaScript: Internationalization API, defect, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox71 | --- | fixed |
People
(Reporter: froydnj, Assigned: Waldo)
References
Details
Attachments
(1 file)
(deleted),
text/x-phabricator-request
|
Details |
Source code in question says:
static constexpr size_t MaxUnitLength() {
// Enable by default when bug 1560664 is fixed.
#if __cplusplus >= 201703L
size_t length = 0;
for (const auto& unit : simpleMeasureUnits) {
length = std::max(length, std::char_traits<char>::length(unit.subtype));
}
return length * 2 + std::char_traits<char>::length("-per-");
#else
...
I assume this is because simpleMeasureUnits
is not constexpr
? Or possibly because the standard library's std::max
isn't constexpr
?
Assignee | ||
Comment 1•5 years ago
|
||
Reporter | ||
Comment 2•5 years ago
|
||
I am currently having to use:
@@ -445,7 +445,8 @@ static constexpr size_t MaxUnitLength() {
#if __cplusplus >= 201703L
size_t length = 0;
for (const auto& unit : simpleMeasureUnits) {
- length = std::max(length, std::char_traits<char>::length(unit.subtype));
+ const size_t subtype_length = std::char_traits<char>::length(unit.subtype);
+ length = length > subtype_length ? length : subtype_length;
}
return length * 2 + std::char_traits<char>::length("-per-");
#else
to deal with not-constexpr
std::max
functions, FWIW.
Assignee | ||
Comment 3•5 years ago
|
||
That's pretty strange -- std::max
has been constexpr
since C++14 per https://en.cppreference.com/w/cpp/algorithm/max and N3936 that's basically C++14 but free. Are we using a bad STL or something these days?
Reporter | ||
Comment 4•5 years ago
|
||
GCC 6.4+, at least, appear to properly declare things as constexpr
.
I'm seeing this on an aarch64-linux cross-build, so maybe we don't have the correct headers there somehow?
Reporter | ||
Comment 5•5 years ago
|
||
I don't understand what's going on the the aarch64 cross build; the system libraries are GCC 6, which I have verified do understand how to do constexpr max()
.
Comment 6•5 years ago
|
||
Hmm, interesting. https://godbolt.org/z/Lc7qOf works with just const
in GCC >= 8; GCC < 8 or any Clang need constexpr
. And std::char_traits<char>::length
only works in constexpr
contexts for GCC > 7.2.
Assignee | ||
Comment 7•5 years ago
|
||
Whoops, I never landed this? Fixed now. *stabs lando for preventing him from regularly landing his own patches*
Comment 9•5 years ago
|
||
bugherder |
Updated•5 years ago
|
Description
•