[clang] [clang] Fix nullptr dereference when checking friend default comparison (PR #132320)

Chongzhi Deng via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 21 00:56:45 PDT 2025


https://github.com/BruceAko updated https://github.com/llvm/llvm-project/pull/132320

>From 3268a174a694eacb57fe13b732ef961dc94bee0b Mon Sep 17 00:00:00 2001
From: BruceAko <chongzhi at hust.edu.cn>
Date: Fri, 21 Mar 2025 07:54:16 +0000
Subject: [PATCH] [clang] Fix nullptr dereference when checking friend default
 comparison

Fix comparison check for explicitly defaulted functions by using declaresSameEntity for friend declarations.
---
 clang/lib/Sema/SemaDeclCXX.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index a1551e8027cd3..ad4a6779a1fcf 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -9039,8 +9039,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;



More information about the cfe-commits mailing list