[llvm-bugs] [Bug 40989] New: decltype resolution ignores SFINAE

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 6 16:21:34 PST 2019


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: unassignedclangbugs at nondot.org
          Reporter: Simon.Richter at hogyros.de
                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

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190307/2f83df76/attachment.html>


More information about the llvm-bugs mailing list