[libc++] Ambiguous call to std::max
leads to complication failure
#121713
Labels
libc++
libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
The following code snippet, which utilizes
vector<bool>
with a custom-sized allocator withsize_type = std::uint16_t
anddifference_type = std::int16_t
, fails to compile due to an ambiguous call tostd::max
withinvector<bool>
:Godbolt Link
This code produces the following compilation error in libc++:
Root cause analysis
The root cause to the complication error is due to the following ambiguous
std::max
call withinvector<bool>
:llvm-project/libcxx/include/__vector/vector_bool.h
Line 529 in f4230b4
In this context with the custom-sized allocator, the first operand's result type is
int
due to integral promotion in the arithmetic involvingint
andstd::uint16_t
. Meanwhile, the second operand retains thesize_type
type (i.e.,std::uint16_t
). This type mismatch leads to a failure in template type argument deduction forstd::max<T>
, resulting in the compilation error.Proposed solution:
I've already submitted a PR #119801 to fix this issue. The solution is straightforward: explicitly specify the template type argument for
std::max
to ensure consistent types for both operands.The text was updated successfully, but these errors were encountered: