The following example demonstrates the issue:
============================
#include <utility>
#include <iostream>
#define INLINE_FRIEND
class Outer {
enum InnerEnum {
Value0 = 0
};
typedef std::pair<InnerEnum, int> InnerPair;
friend bool operator==(const InnerPair& lhs, const InnerPair& rhs)
#ifdef INLINE_FRIEND
{
return lhs.first == rhs.first;
}
#else
;
#endif
public:
static void test();
};
#ifndef INLINE_FRIEND
bool operator==(const Outer::InnerPair& lhs, const Outer::InnerPair& rhs)
{
return lhs.first == rhs.first;
}
#endif
void Outer::test()
{
InnerPair pair1(Value0, 0);
InnerPair pair2(Value0, 1);
std::cout << (pair1 == pair2 ? "==" : "!=") << std::endl;
}
int main()
{
Outer::test();
return 0;
}
============================
When compiled with 4.1/4.2/4.3 this prints "!=", with 3.3/3.4 - '=='.
I believe that 3.3/3.4 were doing "the right thing" (unless I'm misreading the
standard)
I'm not sure if 4.0 is affected by this since I do not have it installed.
--
Summary: operator overloads defined as a friend within a class
are not always correctly resolved
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: nick dot orlov at mail dot ru
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35631