[clang] fb7135e - [Clang] fixed clang frontend crash with friend class declaration and overload == (#133878)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 2 18:11:31 PDT 2025
Author: Ankur Ahir
Date: 2025-04-03T09:11:27+08:00
New Revision: fb7135ec5239a45b43fae6206f7409fd77c50b9f
URL: https://github.com/llvm/llvm-project/commit/fb7135ec5239a45b43fae6206f7409fd77c50b9f
DIFF: https://github.com/llvm/llvm-project/commit/fb7135ec5239a45b43fae6206f7409fd77c50b9f.diff
LOG: [Clang] fixed clang frontend crash with friend class declaration and overload == (#133878)
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fb6b0baae16b..5e8df45e71d54 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -365,6 +365,7 @@ Bug Fixes to Attribute Support
Bug Fixes to C++ Support
^^^^^^^^^^^^^^^^^^^^^^^^
+- Clang now supports implicitly defined comparison operators for friend declarations. (#GH132249)
- Clang now diagnoses copy constructors taking the class by value in template instantiations. (#GH130866)
- Clang is now better at keeping track of friend function template instance contexts. (#GH55509)
- Clang now prints the correct instantiation context for diagnostics suppressed
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 2142582adf6e9..96c0470198e35 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -9006,8 +9006,7 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *FD,
return true;
if (llvm::none_of(RD->friends(), [&](const FriendDecl *F) {
- return FD->getCanonicalDecl() ==
- F->getFriendDecl()->getCanonicalDecl();
+ return declaresSameEntity(F->getFriendDecl(), FD);
})) {
Diag(FD->getLocation(), diag::err_defaulted_comparison_not_friend)
<< int(DCK) << int(0) << RD;
diff --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
index a195e0548152d..f3e241c7bbd51 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -285,3 +285,15 @@ struct j {
};
bool j::operator==(const j &) const = default;
}
+
+namespace evil2 {
+ struct k {
+ };
+
+ struct l {
+ friend bool operator==(const l& a, const l& b);
+ friend class k;
+ };
+
+ bool operator==(const l& a, const l& b) = default;
+}
More information about the cfe-commits
mailing list