<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - SFINAE issue with constexpr operator"
   href="https://llvm.org/bugs/show_bug.cgi?id=30763">30763</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>SFINAE issue with constexpr operator
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.9
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </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>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>officesamurai@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=17476" name="attach_17476" title="test code (also in the text)">attachment 17476</a> <a href="attachment.cgi?id=17476&action=edit" title="test code (also in the text)">[details]</a></span>
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.</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>