[clang] [Clang][Sema] Don't assert on friend declarators with an empty name (PR #223213)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 16 03:38:42 PDT 2026
================
@@ -18580,7 +18580,21 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, Declarator &D,
CXXScopeSpec &SS = D.getCXXScopeSpec();
DeclarationNameInfo NameInfo = GetNameForDeclarator(D);
- assert(NameInfo.getName());
+
+ // GetNameForDeclarator (via GetNameFromUnqualifiedId) can fail and return
+ // an empty name after it has already diagnosed the problem itself. For
+ // example, a declarator that was parsed as a deduction-guide name (see
+ // Sema::isDeductionGuideName) but does not actually name a class
+ // template, such as a template template parameter used as in
+ // 'friend C();' where C is a 'template <typename> class' parameter.
+ // [temp.deduct.guide]p3 only permits the simple-template-id to name a
+ // class template, so this is ill-formed, but it's still a valid
+ // declarator syntactically and reaches here. Recover the same way
+ // HandleDeclarator does for the analogous non-friend case rather than
+ // asserting.
----------------
zyn0217 wrote:
```suggestion
```
https://github.com/llvm/llvm-project/pull/223213
More information about the cfe-commits
mailing list