[Bug c++/90203] New: Can't compare "const std::pair" with "std::pair"

2019-04-22 Thread shreyans.doshi94 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90203

Bug ID: 90203
   Summary: Can't compare "const std::pair" with
"std::pair"
   Product: gcc
   Version: 8.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: shreyans.doshi94 at gmail dot com
  Target Milestone: ---

Created attachment 46221
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46221&action=edit
Complete error message

The following code works fine:

#include 
#include 
#include 

using namespace std;

int main()
{
map a = {{1, 2}, {3, 4}};
pair x = {1, 2};
cout << count(a.begin(), a.end(), x);  // Outputs 1
return 0;
}

But when I do the same thing inside count function using make_pair, it doesn't
work:

#include 
#include 
#include 

using namespace std;

int main()
{
map a = {{1, 2}, {3, 4}};
cout << count(a.begin(), a.end(), make_pair(1, 2)); //
Compilation error
return 0;
}

Exact error message:
/usr/include/c++/7/bits/predefined_ops.h:241:17: error: no match for
‘operator==’ (operand types are ‘std::pair’ and ‘const
std::pair’)
  { return *__it == _M_value; }
   ~~^~~

I've attached complete error message in a file with Description "Complete error
message" for reference. But I believe the issues is easy to reproduce on local
machine as well

Surprisingly, const pair and pair are not comparable,
which it should be in such cases. Ideally, if a container is const, it should
imply that all the underlying members are also const.

To play around a little bit, I also tried to keep the type of x in the first
snippet to be "pair" and it starts giving similar error
that it can't compare "pair" with "pair".
Although this should have worked, but logically thinking, the case above where
the whole pair is const should be more likely to work in my opinion.

Although the error message I've given is from gcc7, I've tried the same thing
on gcc8.3, clang8 and even MSVC19.20 to see if any other compiler has the same
issue and it turns out that all of them are giving me same error.

Compilation flag: -g3 -std=c++17 -O3
I've also tried adding "-Wall -Werror -Wpedantic" and it gives me same error.

I'll be happy to give any more info if required by anyone.

[Bug libstdc++/90203] Can't compare "const std::pair" with "std::pair"

2019-04-22 Thread shreyans.doshi94 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90203

--- Comment #4 from Shreyans Doshi  ---
Yeah, I checked that scenario as well. Logically both are same, but
compiler doesn't agree to that.
But as pointed out by other members, it is not just the compiler,
surprisingly it is not present in the standard itself. So, I guess I'll
have to propose it C++ std committee.

Thanks for looking into it anyways.

Regards
Shreyans

On Mon, Apr 22, 2019 at 6:34 PM redi at gcc dot gnu.org <
gcc-bugzi...@gcc.gnu.org> wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90203
>
> --- Comment #3 from Jonathan Wakely  ---
> (In reply to Shreyans Doshi from comment #0)
> >
> > Surprisingly, const pair and pair are not
> > comparable, which it should be in such cases. Ideally, if a container is
> > const, it should imply that all the underlying members are also const.
> >
>
> const pair does imply the members are const, but it's still not the
> same
> type as pair, and so isn't comparable.
>
> --
> You are receiving this mail because:
> You are on the CC list for the bug.
> You reported the bug.