[llvm-bugs] [Bug 48611] New: user-defined template operator < not used
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Dec 28 01:06:22 PST 2020
https://bugs.llvm.org/show_bug.cgi?id=48611
Bug ID: 48611
Summary: user-defined template operator < not used
Product: clang
Version: unspecified
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: tobias.loew at steag.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
Hi,
in the following code the user-defined operator< for enum E1 is used, but the
user-defined template operator< for enum E2 is not used - the built-in
operator< is used instead for E2. Even though the standard states that a user
user-defined relational operator candidate hides the built-in operator during
overload resolution (https://eel.is/c++draft/over.built#1)
NB: when I change "operator <" to "operator &" (with appropriate return types)
then the user-defined overload is used in both cases.
I searched the standard, if there is a specialization for relational operators
during overload resolution, but I couldn't find one.
Tobias
-----------------------------------------------------------------
#include <iostream>
enum E1 {
e1_a
};
inline bool operator<(E1, E1) {
return true;
}
enum E2 {
e2_a
};
template<class E>
inline bool operator<(E, E) {
return true;
}
int main()
{
if (E1::e1_a < E1::e1_a) {
std::cout << "user-defined operator used for E1\n";
} else {
std::cout << "builtin operator used for E1\n";
}
if (E2::e2_a < E2::e2_a) {
std::cout << "user-defined operator used for E2\n";
} else {
std::cout << "builtin operator used for E2\n";
}
}
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201228/7561d1c3/attachment.html>
More information about the llvm-bugs
mailing list