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

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