public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104785] New: Generated defaulted constexpr operator== produces wrong code
@ 2022-03-04 15:29 delleyves at gmx dot ch
2022-03-05 4:43 ` [Bug c++/104785] " pinskia at gcc dot gnu.org
2022-03-05 4:45 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: delleyves at gmx dot ch @ 2022-03-04 15:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104785
Bug ID: 104785
Summary: Generated defaulted constexpr operator== produces
wrong code
Product: gcc
Version: 11.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: delleyves at gmx dot ch
Target Milestone: ---
It seems that the code generated for a defaulted constexpr `operator==` for a
struct that inherits a field whose type contains another such `operator==` does
not take that field into account. Removing constexpr on the top-most
`operator==` restores correct behaviour. Therefore, this is likely related to
#102490, although that one deals with bitfields. The behaviour seems to be
present on all versions of GCC supporting C++20's defaulted equality operators,
I did test 10.1 through 11.2 on godbolt.
In the following example (godbolt link: https://gcc.godbolt.org/z/7nE67fKxc),
the result is wrong only for the `D` type:
#include <iostream>
struct A
{
int a;
[[nodiscard]] constexpr bool operator==(const A&) const = default;
};
struct B
{
A a;
int b;
[[nodiscard]] constexpr bool operator==(const B&) const = default;
};
struct C : B
{
int c;
[[nodiscard]] bool operator==(const C&) const = default;
};
struct D : B
{
int d;
[[nodiscard]] constexpr bool operator==(const D&) const = default;
};
std::ostream &operator<<(std::ostream &os, const A &a) {
os << "A("<<a.a<<")";
return os;
}
std::ostream &operator<<(std::ostream &os, const B &b) {
os << "B("<<b.a<<", "<<b.b<<")";
return os;
}
std::ostream &operator<<(std::ostream &os, const C &c) {
os << "C("<<c.a<<", "<<c.b<<", "<<c.c<<")";
return os;
}
std::ostream &operator<<(std::ostream &os, const D &d) {
os << "D("<<d.a<<", "<<d.b<<", "<<d.d<<")";
return os;
}
int main()
{
A a1{1}, a2{2};
B b1{a1,2}, b2{a2,2};
C c1{b1,3}, c2{b2,3};
D d1{b1,3}, d2{b2,3};
#define CHECK(x,y) std::cout << x << " == " << y << "? " << ((x==y) ? "true" :
"false") << std::endl;
CHECK(a1,a2);
CHECK(b1,b2);
CHECK(c1,c2);
CHECK(d1,d2);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/104785] Generated defaulted constexpr operator== produces wrong code
2022-03-04 15:29 [Bug c++/104785] New: Generated defaulted constexpr operator== produces wrong code delleyves at gmx dot ch
@ 2022-03-05 4:43 ` pinskia at gcc dot gnu.org
2022-03-05 4:45 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-03-05 4:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104785
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |needs-bisection
Known to work| |12.0
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Looks fixed on the trunk.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/104785] Generated defaulted constexpr operator== produces wrong code
2022-03-04 15:29 [Bug c++/104785] New: Generated defaulted constexpr operator== produces wrong code delleyves at gmx dot ch
2022-03-05 4:43 ` [Bug c++/104785] " pinskia at gcc dot gnu.org
@ 2022-03-05 4:45 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-03-05 4:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104785
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 98712.
*** This bug has been marked as a duplicate of bug 98712 ***
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-05 4:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-04 15:29 [Bug c++/104785] New: Generated defaulted constexpr operator== produces wrong code delleyves at gmx dot ch
2022-03-05 4:43 ` [Bug c++/104785] " pinskia at gcc dot gnu.org
2022-03-05 4:45 ` pinskia at gcc dot gnu.org
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).