[clang] [clang] fix crash on qualified friend function definitions (PR #186398)

via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 10 08:03:45 PDT 2026


================
@@ -18319,6 +18319,18 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, Declarator &D,
       DiagnoseUnexpandedParameterPack(SS, UPPC_FriendDeclaration))
     return nullptr;
 
+  if (D.isFunctionDefinition() && SS.isNotEmpty()) {
+    auto Kind = SS.getScopeRep().getKind();
+    if (Kind == NestedNameSpecifier::Kind::Global ||
+        Kind == NestedNameSpecifier::Kind::Namespace) {
+      if (D.getName().getKind() != UnqualifiedIdKind::IK_TemplateId) {
+        Diag(SS.getRange().getBegin(), diag::err_qualified_friend_def)
+            << SS.getScopeRep() << FixItHint::CreateRemoval(SS.getRange());
+        SS.clear();
+      }
+    }
+  }
----------------
Serosh-commits wrote:

> Nit: Can you reduce the level of nesting here? A bit excessive, you can certainly move the last condition into the first one.

sure 😃

https://github.com/llvm/llvm-project/pull/186398


More information about the cfe-commits mailing list