[PATCH] D151625: [clang] Add `clang::equality_operator_compares_members_lexicographically`

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 24 08:29:59 PDT 2023


aaron.ballman added inline comments.


================
Comment at: clang/include/clang/Basic/AttrDocs.td:3525
+  let Content = [{
+On classes, the ``equality_operator_compares_members_lexicographically``
+attribute informs clang that a call to ``operator==(const T&, const T&)`` is
----------------
The docs don't make it clear what the ramifications are of using the attribute. Do you get better codegen? Different diagnostics? That sort of thing.

It'd probably help for the docs to have a short code example showing what the difference the attribute makes.

Also, should we explicitly define it as UB if the user applies the attribute to something and the equivalence requirements aren't met?

If the attribute is written on a structure that's used as a base class, does the derived class automatically "inherit" the behavior as well? Or do derived classes have to be redeclared with the attribute? Is it reasonable for a base class which does not have the attribute to be inherited by a derived class which adds the attribute?

(I'm kind of wondering whether there are situations in which we want to diagnose use of the attribute to help programmers avoid mistakes.)


================
Comment at: clang/include/clang/Basic/AttrDocs.td:3531-3533
+On enums, the attribute guarantees that there are either no custom comparison
+operators defined, or any that defined are quivalent to the builtin comparison
+operator.
----------------



================
Comment at: clang/test/SemaCXX/attr-equality-operator-compares-members-lexicographically.cpp:1
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s -std=c++20
+
----------------
Is the triple necessary?


================
Comment at: clang/test/SemaCXX/attr-equality-operator-compares-members-lexicographically.cpp:72
+
+// TODO: This is trivially equality comparable
+struct [[clang::equality_operator_compares_members_lexicographically]] NotTriviallyEqualityComparableBitfieldFilled {
----------------
FIXME?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151625/new/

https://reviews.llvm.org/D151625



More information about the cfe-commits mailing list