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; 4+ 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] 4+ 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; 4+ 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] 4+ 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; 4+ 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] 4+ messages in thread

* [Bug c++/35631] operator overloads defined as a friend within a class are not always correctly resolved
       [not found] <bug-35631-4@http.gcc.gnu.org/bugzilla/>
@ 2015-03-27 18:11 ` paolo.carlini at oracle dot com
  0 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-27 18:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=35631

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|gcc-bugs at gcc dot gnu.org        |
      Known to work|                            |4.8.0, 4.9.0, 5.0
         Resolution|---                         |WORKSFORME

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Fixed long time ago.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-03-27 17:58 UTC | newest]

Thread overview: 4+ 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
     [not found] <bug-35631-4@http.gcc.gnu.org/bugzilla/>
2015-03-27 18:11 ` paolo.carlini at oracle dot com

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).