<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - string_view equality operator does not compile with clang-cl"
href="https://bugs.llvm.org/show_bug.cgi?id=50001">50001</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>string_view equality operator does not compile with clang-cl
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>mhochk@microsoft.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
</td>
</tr></table>
<p>
<div>
<pre>Context first:
There is a name-mangling issue/bug/limitation in clang-cl (doesn't appear to
impact clang directly) easily repro'd by attempting to compile the following
(locally named clang-cl-issue.cpp):
template <class T>
struct X {
T member;
};
template <class T>
struct ConvertibleToX {
operator X<T>() { return {T{}}; }
};
template <class T>
struct identity {
using type = T;
};
template <class T>
bool operator==(const X<T> lhs, const X<T> rhs) {
return (true);
}
template <class T>
bool operator==(const X<T> lhs, const typename identity<X<T>>::type rhs) {
return (true);
}
template <class T>
bool operator==(const typename identity<X<T>>::type lhs, const X<T> rhs) {
return (true);
}
int main() {
X<int> xVal{42};
ConvertibleToX<int> xConvVal;
bool result = xVal == xVal;
result = xVal == xConvVal;
result = xConvVal == xVal;
return result ? 1 : 0;
}
RESULT:
clang-cl-issue.cpp(18,6): error: definition with same mangled name
'??$?8H@@YA_NU?$X@H@@0@Z' as another definition
bool operator==(const X<T> lhs, const typename identity<X<T>>::type rhs) {
^
clang-cl-issue.cpp(14,6): note: previous definition is here
bool operator==(const X<T> lhs, const X<T> rhs) {
^
clang-cl-issue.cpp(22,6): error: definition with same mangled name
'??$?8H@@YA_NU?$X@H@@0@Z' as another definition
bool operator==(const typename identity<X<T>>::type lhs, const X<T> rhs) {
^
clang-cl-issue.cpp(14,6): note: previous definition is here
bool operator==(const X<T> lhs, const X<T> rhs) {
This issue is relevant to the libc++ component because the string_view
implementation currently uses the same pattern, raising the same errors with
clang-cl with very simple usage. For example, attempting to compile:
#include <string>
#include <string_view>
#include <unordered_set>
constexpr std::string_view kSomeView("Hello");
bool TestFunction(
const std::unordered_set<std::string_view>& telemetry,
const std::string& s) noexcept
{
if (telemetry.find(s) != telemetry.end()) {
return s == kSomeView;
}
return false;
}
RESULT:
{MyLocalPath}\libcxx\include\string_view(614,6): error: definition with same
mangled name
'??$?8DU?$char_traits@D@__1@std@@@__1@std@@YA_NV?$basic_string_view@DU?$char_traits@D@__1@std@@@01@0@Z'
as another definition
bool operator==(basic_string_view<_CharT, _Traits> __lhs,
^
{MyLocalPath}\libcxx\include\string_view(632,6): note: previous definition is
here
bool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type
__lhs,
^
Though the root issue is with clang-cl, this can be worked around very easily
by adding additional qualifiers to the string_view equality operator templates
to force them to be unique. Added below ", int = 1" and ", int = 2" fixes this
problem for string_view usage.
// [string.view.comparison]
// operator ==
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator==(basic_string_view<_CharT, _Traits> __lhs,
basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
{
if ( __lhs.size() != __rhs.size()) return false;
return __lhs.compare(__rhs) == 0;
}
template<class _CharT, class _Traits, int = 1>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator==(basic_string_view<_CharT, _Traits> __lhs,
typename common_type<basic_string_view<_CharT, _Traits> >::type
__rhs) _NOEXCEPT
{
if ( __lhs.size() != __rhs.size()) return false;
return __lhs.compare(__rhs) == 0;
}
template<class _CharT, class _Traits, int = 2>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type
__lhs,
basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
{
if ( __lhs.size() != __rhs.size()) return false;
return __lhs.compare(__rhs) == 0;
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>