public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94924] New: Default equality operator for C-array compares addresses, not data
@ 2020-05-02 14:12 rhalbersma at gmail dot com
  2020-05-06  0:36 ` [Bug c++/94924] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: rhalbersma at gmail dot com @ 2020-05-02 14:12 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94924
           Summary: Default equality operator for C-array compares
                    addresses, not data
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rhalbersma at gmail dot com
  Target Milestone: ---

It appears that the default op== for a C-array has array-to-pointer decay
applied and does not compare the underlying array data.

struct S {
    int data[1];
    bool operator==(const S&) const = default;
};

int main()
{
    static_assert(S{1} != S{1});
    constexpr auto s = S{1};
    static_assert(s == s);
}

Tested on tip-of-trunk at Wandbox:
https://wandbox.org/permlink/YxUv5dFs7mSGlNBx

Works correctly on Clang >= 10.

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

* [Bug c++/94924] Default equality operator for C-array compares addresses, not data
  2020-05-02 14:12 [Bug c++/94924] New: Default equality operator for C-array compares addresses, not data rhalbersma at gmail dot com
@ 2020-05-06  0:36 ` redi at gcc dot gnu.org
  2020-05-12 11:49 ` rhalbersma at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-05-06  0:36 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-05-06
             Status|UNCONFIRMED                 |NEW

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

* [Bug c++/94924] Default equality operator for C-array compares addresses, not data
  2020-05-02 14:12 [Bug c++/94924] New: Default equality operator for C-array compares addresses, not data rhalbersma at gmail dot com
  2020-05-06  0:36 ` [Bug c++/94924] " redi at gcc dot gnu.org
@ 2020-05-12 11:49 ` rhalbersma at gmail dot com
  2020-05-12 12:08 ` rhalbersma at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rhalbersma at gmail dot com @ 2020-05-12 11:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from rhalbersma <rhalbersma at gmail dot com> ---
I just became aware of [depr.array.comp] in N4861

"Equality and relational comparisons (7.6.10, 7.6.9) between two operands of
array type are deprecated."

This is very surprising to say the least and disqualifies default op= for any
class containing a C-array. 

But in any case, should such code generate a warning message? And this bug be
closed?

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

* [Bug c++/94924] Default equality operator for C-array compares addresses, not data
  2020-05-02 14:12 [Bug c++/94924] New: Default equality operator for C-array compares addresses, not data rhalbersma at gmail dot com
  2020-05-06  0:36 ` [Bug c++/94924] " redi at gcc dot gnu.org
  2020-05-12 11:49 ` rhalbersma at gmail dot com
@ 2020-05-12 12:08 ` rhalbersma at gmail dot com
  2021-04-22 19:32 ` ppalka at gcc dot gnu.org
  2022-12-26 15:50 ` rhalbersma at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: rhalbersma at gmail dot com @ 2020-05-12 12:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from rhalbersma <rhalbersma at gmail dot com> ---
OK, Alisdair Meredith points out on Twitter that in [class.compare.default]/6
there is a special sentence on array class data members

In that list, any subobject of array type is recursively expanded to the
sequence of its elements, in the order of increasing subscript.

So only direct array comparisons are deprecated.

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

* [Bug c++/94924] Default equality operator for C-array compares addresses, not data
  2020-05-02 14:12 [Bug c++/94924] New: Default equality operator for C-array compares addresses, not data rhalbersma at gmail dot com
                   ` (2 preceding siblings ...)
  2020-05-12 12:08 ` rhalbersma at gmail dot com
@ 2021-04-22 19:32 ` ppalka at gcc dot gnu.org
  2022-12-26 15:50 ` rhalbersma at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-04-22 19:32 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Looks like a dup of PR93480, which has been fixed for GCC 11.

*** This bug has been marked as a duplicate of bug 93480 ***

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

* [Bug c++/94924] Default equality operator for C-array compares addresses, not data
  2020-05-02 14:12 [Bug c++/94924] New: Default equality operator for C-array compares addresses, not data rhalbersma at gmail dot com
                   ` (3 preceding siblings ...)
  2021-04-22 19:32 ` ppalka at gcc dot gnu.org
@ 2022-12-26 15:50 ` rhalbersma at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: rhalbersma at gmail dot com @ 2022-12-26 15:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from rhalbersma <rhalbersma at gmail dot com> ---
Is there any chance that this bug fix can be backported to gcc 10 also?

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

end of thread, other threads:[~2022-12-26 15:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-02 14:12 [Bug c++/94924] New: Default equality operator for C-array compares addresses, not data rhalbersma at gmail dot com
2020-05-06  0:36 ` [Bug c++/94924] " redi at gcc dot gnu.org
2020-05-12 11:49 ` rhalbersma at gmail dot com
2020-05-12 12:08 ` rhalbersma at gmail dot com
2021-04-22 19:32 ` ppalka at gcc dot gnu.org
2022-12-26 15:50 ` rhalbersma at gmail 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).