public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/35631] New: operator overloads defined as a friend within a class are not always correctly resolved
@ 2008-03-19 2:08 nick dot orlov at mail dot ru
2008-03-19 2:57 ` [Bug c++/35631] " pinskia at gcc dot gnu dot org
2008-03-19 12:45 ` nick dot orlov at mail dot ru
0 siblings, 2 replies; 3+ messages in thread
From: nick dot orlov at mail dot ru @ 2008-03-19 2:08 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/35631] operator overloads defined as a friend within a class are not always correctly resolved
2008-03-19 2:08 [Bug c++/35631] New: operator overloads defined as a friend within a class are not always correctly resolved nick dot orlov at mail dot ru
@ 2008-03-19 2:57 ` pinskia at gcc dot gnu dot org
2008-03-19 12:45 ` nick dot orlov at mail dot ru
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-03-19 2:57 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2008-03-19 02:57 -------
No, 4.1,4.2, and 4.3 are correct.
Read http://gcc.gnu.org/gcc-4.1/changes.html, the "ARM-style name-injection of
friend declarations is no longer the default. " section.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35631
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/35631] operator overloads defined as a friend within a class are not always correctly resolved
2008-03-19 2:08 [Bug c++/35631] New: operator overloads defined as a friend within a class are not always correctly resolved nick dot orlov at mail dot ru
2008-03-19 2:57 ` [Bug c++/35631] " pinskia at gcc dot gnu dot org
@ 2008-03-19 12:45 ` nick dot orlov at mail dot ru
1 sibling, 0 replies; 3+ messages in thread
From: nick dot orlov at mail dot ru @ 2008-03-19 12:45 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from nick dot orlov at mail dot ru 2008-03-19 12:44 -------
Standard says:
11.4.6. A function can be defined in a friend declaration of a class if and
only if the class is a non-local class (9.8), the function name is unqualified,
and the function has namespace scope.
11.4.7 Such a function is implicitly inline. A friend function defined in a
class is in the (lexical) scope of the class in which it is defined. A friend
function defined outside the class is not (3.4.1)
=======
So I would agree, but in my example operator is being called from a (static)
class method.
--
nick dot orlov at mail dot ru changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35631
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-03-19 12:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-19 2:08 [Bug c++/35631] New: operator overloads defined as a friend within a class are not always correctly resolved nick dot orlov at mail dot ru
2008-03-19 2:57 ` [Bug c++/35631] " pinskia at gcc dot gnu dot org
2008-03-19 12:45 ` nick dot orlov at mail dot ru
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).