This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/40804] New: STL: operator>= for pair "hides" general operator>= from std::rel_ops


The fact that std::pair has operator>= defined in namespace std "hides"
oprator>= defined in namespace std::rel_ops, for all classes.

operator>= for pairs is defined in <bits/stl_pair.h>, and it is in namespace
std;

This only happens when " >= " is used from std, as in the case of
"greater_equal".

I use >= as an example, the same happens for (<=, >, .....)

I've tested this behavior with gcc 4.4.0 (on Fedora 11), gcc 4.3.X and 3.4.X
from cygwin.

This small c++ program fails with (compiled as g++ -c foo.cpp)
(If I add -Wall, it reports about ok and bad not being used).

In file included from
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/functional:51,
                 from foo.cpp:3:
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_function.h:
In member function ?bool std::greater_equal<_Tp>::operator()(const _Tp&, const
_Tp&) const [with _Tp = A]?:
foo.cpp:20:   instantiated from here
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_function.h:239:
error: no match for ?operator>=? in ?__x >= __y?


#include <utility>
#include <functional>

using namespace std;
using namespace std::rel_ops;

struct A
{
  bool operator<(const A &) const;
};

void foo1()
{
  bool ok = A() >= A(); // just to check rel_ops is actually included
}

void foo2()
{
  greater_equal<A> ge;
  bool bad = ge(A(), A());
}

The only way to make it compile so far is to add

namespace std
{
  namespace rel_ops
  {
  }
  using namespace rel_ops;
}

so that rel_ops::operator>= is found by "greater_equal".

If I only add 

using namespace std::rel_ops;

in my C++ source code, it is not enough, since (I think) gcc chooses (while
parsing greater_equal) the operator>= defined in std (the only one available at
that time), and when an other one is added later (from rel_ops) it is too late.

Alternatively, if I move operator>= for pair into std::rel_ops everything
works.

I am not sure where is the root of the problem, but my thoughts are

1) why do we need an operator >= for pair? is it not enough the one for all
<T>?
2) why is operator>= for pair in std and not in std::rel_ops?
3) is gcc correct in ignoring operator>= from rel_ops?


-- 
           Summary: STL: operator>= for pair "hides" general operator>= from
                    std::rel_ops
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mariofutire at googlemail dot com


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]