https://github.com/akash-manna-sky updated https://github.com/llvm/llvm-project/pull/221570
>From 2c1671bdacb4754cb2ca1eedcda60e7827d1a06b Mon Sep 17 00:00:00 2001 From: Akash Manna <[email protected]> Date: Sun, 6 Sep 2026 18:58:51 +0530 Subject: [PATCH 1/2] [Clang] Skip invalid fields when synthesizing defaulted comparisons A field whose type carries an address space is already rejected by CheckFieldDecl and marked invalid, but DefaultedComparisonVisitor still visited it when building a defaulted operator== or operator<=>. BuildFieldReferenceExpr then asserted because a member type is never supposed to carry an address space qualifier. Skip invalid fields in visitSubobjects, matching what the other defaulted-member visitors already do. Fixes #194605 --- clang/docs/ReleaseNotes.md | 4 ++++ clang/lib/Sema/SemaDeclCXX.cpp | 3 +++ clang/test/SemaCXX/cxx20-default-compare.cpp | 11 +++++++++++ 3 files changed, 18 insertions(+) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index a49971adef86f..1c190ecbc4547 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -646,6 +646,10 @@ features cannot lower the translation-unit ABI level; - Fixed a crash when a coroutine keyword appeared inside a mem-initializer on a function that is not a constructor. (#GH194298) +- Fixed an assertion when a defaulted comparison operator was synthesized for a + class with an invalid non-static data member, such as one qualified with an + address space. (#GH194605) + #### Bug Fixes to AST Handling - Fixed a non-deterministic ordering of unused local typedefs that made diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 4457ec58902d0..28beb44af987b 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -8203,6 +8203,9 @@ class DefaultedComparisonVisitor { // Unnamed bit-fields are not members ... if (Field->isUnnamedBitField()) continue; + // Skip invalid fields; they have already been diagnosed. + if (Field->isInvalidDecl()) + continue; // Recursively expand anonymous structs. if (Field->isAnonymousStructOrUnion()) { if (visitSubobjects(Results, Field->getType()->getAsCXXRecordDecl(), diff --git a/clang/test/SemaCXX/cxx20-default-compare.cpp b/clang/test/SemaCXX/cxx20-default-compare.cpp index c569e9d866970..fd5b703c566d1 100644 --- a/clang/test/SemaCXX/cxx20-default-compare.cpp +++ b/clang/test/SemaCXX/cxx20-default-compare.cpp @@ -79,3 +79,14 @@ struct S { bool b = (S{} < S{}); // expected-error {{object of type 'S' cannot be compared because its 'operator<=>' is implicitly deleted}} } + +namespace GH194605 { +struct S { + int [[clang::address_space(1)]] i; // expected-error {{field may not be qualified with an address space}} + bool operator==(const S &) const = default; +}; + +static_assert(!__is_trivially_equality_comparable(S)); + +bool f(const S &a, const S &b) { return a == b; } +} >From 060fc5c20d939bd7379f1fcb66e0bb81bd38ac06 Mon Sep 17 00:00:00 2001 From: Akash Manna <[email protected]> Date: Mon, 7 Sep 2026 19:03:06 +0530 Subject: [PATCH 2/2] drop redundant comment --- clang/lib/Sema/SemaDeclCXX.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 28beb44af987b..ac98bdaf22f0c 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -8203,7 +8203,6 @@ class DefaultedComparisonVisitor { // Unnamed bit-fields are not members ... if (Field->isUnnamedBitField()) continue; - // Skip invalid fields; they have already been diagnosed. if (Field->isInvalidDecl()) continue; // Recursively expand anonymous structs. _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
