Author: Akash Manna Date: 2026-09-09T06:43:10-07:00 New Revision: 5282d0c073beba1c2569222ede55ff943d46fcef
URL: https://github.com/llvm/llvm-project/commit/5282d0c073beba1c2569222ede55ff943d46fcef DIFF: https://github.com/llvm/llvm-project/commit/5282d0c073beba1c2569222ede55ff943d46fcef.diff LOG: [Clang] Skip invalid fields when synthesizing defaulted comparisons (#221570) Fixes #194605 `CheckFieldDecl` already rejects `int [[clang::address_space(1)]] i;` and marks the field invalid, but `DefaultedComparisonVisitor` still visited it when synthesizing the defaulted `operator==`. `BuildFieldReferenceExpr` then tripped the `!MemberQuals.hasAddressSpace()` assertion. Both `__is_trivially_equality_comparable(S)` and a plain `a == b` reach that path. `visitSubobjects` now skips invalid fields, the same way `SpecialMemberVisitor` and the copy-assignment synthesis already do. That covers the analyzer and the synthesizer together, and the assertion stays in place since it still holds for valid code. Added: Modified: clang/docs/ReleaseNotes.md clang/lib/Sema/SemaDeclCXX.cpp clang/test/SemaCXX/cxx20-default-compare.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 0fb6dcf59d4c9..59b5c14c59242 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -652,6 +652,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..ac98bdaf22f0c 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -8203,6 +8203,8 @@ class DefaultedComparisonVisitor { // Unnamed bit-fields are not members ... if (Field->isUnnamedBitField()) continue; + 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 4e93298bd17a9..b812aba747ac9 100644 --- a/clang/test/SemaCXX/cxx20-default-compare.cpp +++ b/clang/test/SemaCXX/cxx20-default-compare.cpp @@ -88,3 +88,12 @@ union A { A a; bool b = a == a; } + +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(S{} == S{}); +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
