https://bugs.llvm.org/show_bug.cgi?id=40989

            Bug ID: 40989
           Summary: decltype resolution ignores SFINAE
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++11
          Assignee: unassignedclangb...@nondot.org
          Reporter: simon.rich...@hogyros.de
                CC: blitzrak...@gmail.com, dgre...@apple.com,
                    erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
                    richard-l...@metafoo.co.uk

GCC exhibits the same bug, see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89564

This is related, but not identical to #40988.

I'm trying to build a commutative operator+ for a class, as a freestanding
template operator+ that accepts my class on the right hand side and reverses
the argument order:

#include <type_traits>

    struct one {};

    struct two
    {
        two() { }
        two(one const &) { }
        operator one() const { return one{}; }
    };

    template<typename T>
    auto operator+(T const &lhs, two const &rhs) -> typename
std::enable_if<!std::is_same<T, two>::value, decltype(rhs + lhs)>::type
    {
        return rhs + lhs;
    }

    void test()
    {
        one o;
        two t;
        auto a = o + t;
    }

This code should have been rejected, because no usable operator+ exists for the
expression "rhs + lhs". Instead, the template is specialized recursively trying
to resolve the decltype.

icc and MSVC correctly reject this code with the expected diagnostic.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to