[llvm-bugs] [Bug 43400] New: template friend is redefinition

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Sep 22 11:00:52 PDT 2019


            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: unassignedclangbugs at nondot.org
          Reporter: Casey at Carter.net
                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

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

Compiling this well-formed program:

    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

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

More information about the llvm-bugs mailing list