[LLVMbugs] [Bug 8007] New: friend function either not instantiated or not injected

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Aug 27 05:03:35 PDT 2010


http://llvm.org/bugs/show_bug.cgi?id=8007

           Summary: friend function either not instantiated or not
                    injected
           Product: clang
           Version: trunk
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: ggreif at gmail.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


Please compile the attached file, reproduced here too:

###########################
#include <iostream>

template <typename STRUCT_TYPE>
struct Streamer
{
    friend std::ostream& operator << (std::ostream& o, const STRUCT_TYPE& f)
        {
            Streamer s(f);
            s(o);
            return o;
        }

    Streamer(const STRUCT_TYPE& s)
        : s(s)
        {}

    const STRUCT_TYPE& s;

    void operator () (std::ostream&) const;
};


typedef struct Foo {} Foo;

// this does not help either:
template struct Streamer<Foo>;

template <>
void Streamer<Foo>::operator () (std::ostream& o) const
{
}

int main(void)
{
    Foo foo;
    std::cout << foo;
}
###########################

I get:

friend-instantiate.cpp:36:15: error: invalid operands to binary expression
('ostream' (aka 'basic_ostream<char>') and 'Foo' (aka 'Foo'))
    std::cout << foo;
    ~~~~~~~~~ ^  ~~~

gcc (v3.4.6) does compile this.


I suppose that the friend operator function is either not instantiated
or not injected into the enclosing scope.

Even explicitly instantiating the template does nor help (as commented in the
code).

Offtopic, but funny, how the error message issues an "aka" with the same name.
I guess this should be suppressed as it can be quite confusing for long (but
identical) names.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list