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

            Bug ID: 43400
           Summary: template friend is redefinition
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangb...@nondot.org
          Reporter: ca...@carter.net
                CC: blitzrak...@gmail.com, dgre...@apple.com,
                    erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
                    richard-l...@metafoo.co.uk

Created attachment 22540
  --> https://bugs.llvm.org/attachment.cgi?id=22540&action=edit
Repro

Compiling this well-formed program:

    template<class>
    constexpr bool is_lvalue_reference = false;
    template<class T>
    constexpr bool is_lvalue_reference<T&> = true;

    template<bool> struct int_if_ {};
    template<> struct int_if_<true> { using type = int; };
    template<bool B> using int_if = typename int_if_<B>::type;

    struct Derived;

    struct Base {
        template<class T>
        friend void operator|(T&, Derived const&) = delete;

        template<class T, int_if<!is_lvalue_reference<T>> = 0>
        friend T operator|(T&& t, Derived const&) {
            return static_cast<T&&>(t);
        }
    };

    struct Derived : Base {};

    int main() {
        struct vector {};
        vector v;
        v = static_cast<vector&&>(v) | Derived{};
    }

produces diagnostics:

    repro.cpp(15,17): error: redefinition of 'operator|'
        friend void operator|(T&, Derived const&) = delete;
                    ^
    repro.cpp(28,34): note: in instantiation of function template
specialization 'operator|<vector>' requested here
        v = static_cast<vector&&>(v) | Derived{};
                                     ^
    repro.cpp(15,17): note: previous definition is here
        friend void operator|(T&, Derived const&) = delete;
                    ^
    1 error generated.

The problem seems to reproduce on every version of Clang I try, with C++11 or
later.

This doesn't seem to be a duplicate of the other "friend redefinition" bugs
(#35012 and #41523), since it's a template friend of a non-template class, but
I could be mistaken.

-- 
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