tint: fix compile error on macos wrt operator<<
Building tint_unittests on macos with AppleClang failed with, for example:
error: invalid operands to binary expression ('std::__1::basic_ostream<char>' and 'const tint::core::ir::Usage')
return out << key.Value();
This was caused by hashmap_base.h's operator<< erroneously detecting that the
stream object << rhs was available when using
traits::HasOperatorShiftLeft<STREAM, T>. The problem was that the expression
"std::declval<LHS> << std::declval<RHS>" was being used to test if the
expression is valid; however, std::declval returns an r-value reference, so this
was testing "r-value lhs << r-value rhs", and for stream objects, the lhs needs
to be an l-value (typically accepts const& and &). So we fix this by making it
"std::declval<LHS&>" to ensure it always evaluates to an lvalue.
Change-Id: Id722a87204cf998a21130f17b9d3377c487cb890
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/178264
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/utils/traits/traits.h b/src/tint/utils/traits/traits.h
index 669a254..b23f264 100644
--- a/src/tint/utils/traits/traits.h
+++ b/src/tint/utils/traits/traits.h
@@ -267,7 +267,7 @@
template <typename LHS, typename RHS>
struct HasOperatorShiftLeft<LHS,
RHS,
- std::void_t<decltype((std::declval<LHS>() << std::declval<RHS>()))>>
+ std::void_t<decltype(std::declval<LHS&>() << std::declval<RHS>())>>
: std::true_type {};
} // namespace detail