When defining a friend function in a template class it does not get correctly
defined if the class instantiation comes after the function has been already
called. Note: this happens even if you pre-declare the function in its correct
context before the same function is called. 
The following is a code sample that reproduces the bug. Note that this has been
already discussed and concluded that this is valid c++ standard-compliant code
(precisely here:
http://groups.google.com/group/comp.lang.c++/browse_frm/thread/493afd501c807ffe#).

-- code --

void Function();

int main(int argc, char* argv[])
{
        Function(); // This does not work

}

template <typename T>
class Test
{
public:
        friend void Function() { printf("Function()"); getchar(); }

};

template class Test<int>;

-- end code --


-- 
           Summary: Template friend function injection
           Product: gcc
           Version: 4.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: H9XLrv5oXVNvHiUI at spambox dot us


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38392

Reply via email to