[llvm-bugs] [Bug 30763] New: SFINAE issue with constexpr operator
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Oct 21 11:02:13 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=30763
Bug ID: 30763
Summary: SFINAE issue with constexpr operator
Product: clang
Version: 3.9
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: officesamurai at gmail.com
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
Classification: Unclassified
Created attachment 17476
--> https://llvm.org/bugs/attachment.cgi?id=17476&action=edit
test code (also in the text)
The following code fails to compile:
#include <type_traits>
#include <utility>
template <typename TT1, typename TT2>
struct Helper
{
template <typename T1, typename T2>
static auto test(int) -> decltype(std::declval<T1>() == std::declval<T2>(),
std::true_type());
template <typename T1, typename T2>
static auto test(...) -> std::false_type;
using Result = decltype(test<TT1, TT2>(0));
};
template <typename TT1, typename TT2>
constexpr bool isEqualityComparable()
{
using Result = typename Helper<TT1, TT2>::Result;
return Result::value;
}
struct S
{
};
template <typename T>
struct Wrapper
{
T t;
};
// Removing constexpr here will make the code compilable
template <typename T1, typename T2>
constexpr bool operator==(const Wrapper<T1>& w1, const Wrapper<T2>& w2)
{
return w1.t == w2.t;
}
using W = Wrapper<S>;
int main()
{
isEqualityComparable<W, W>();
}
The result is:
$ clang++-3.9 error_test.cpp -std=c++11
error_test.cpp:37:17: error: invalid operands to binary expression ('const S'
and 'const S')
return w1.t == w2.t;
~~~~ ^ ~~~~
error_test.cpp:8:58: note: in instantiation of function template specialization
'operator==<S, S>' requested here
static auto test(int) -> decltype(std::declval<T1>() == std::declval<T2>(),
std::true_type());
^
error_test.cpp:13:29: note: while substituting explicitly-specified template
arguments into function template 'test'
using Result = decltype(test<TT1, TT2>(0));
^
error_test.cpp:19:29: note: in instantiation of template class
'Helper<Wrapper<S>, Wrapper<S> >' requested here
using Result = typename Helper<TT1, TT2>::Result;
^
error_test.cpp:44:5: note: in instantiation of function template specialization
'isEqualityComparable<Wrapper<S>, Wrapper<S> >' requested here
isEqualityComparable<W, W>();
^
error_test.cpp:35:16: note: candidate template ignored: could not match
'Wrapper<type-parameter-0-0>' against 'const S'
constexpr bool operator==(const Wrapper<T1>& w1, const Wrapper<T2>& w2)
Also:
1) -std=c++14 gives the same result,
2) removing constexpr from operator== fixes the problem,
3) GCC 4.9.3 produces a similar error while GCC 5.2.0 compiles it without
errors.
--
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/20161021/ff694ecb/attachment.html>
More information about the llvm-bugs
mailing list