[clang] [Clang] Implement C++26’s P2893R3 ‘Variadic friends’ (PR #101448)

via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 6 09:22:37 PDT 2024


================
@@ -17354,12 +17354,18 @@ Decl *Sema::BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc,
 DeclResult Sema::ActOnTemplatedFriendTag(
     Scope *S, SourceLocation FriendLoc, unsigned TagSpec, SourceLocation TagLoc,
     CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc,
-    const ParsedAttributesView &Attr, MultiTemplateParamsArg TempParamLists) {
+    SourceLocation EllipsisLoc, const ParsedAttributesView &Attr,
+    MultiTemplateParamsArg TempParamLists) {
   TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForTypeSpec(TagSpec);
 
   bool IsMemberSpecialization = false;
   bool Invalid = false;
 
+  // FIXME: This works for now; revisit once we support packs in NNSs.
+  if (EllipsisLoc.isValid())
+    Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
+        << SourceRange(FriendLoc, NameLoc);
+
----------------
Sirraide wrote:

Iirc, ‘all of the invalid ones involving templates’ for want of a better way of putting it. This seems to work for any friend declarations w/ a template-head that we can’t handle anyway (because the NNS contains an unexpanded pack or is dependent). This is not a particularly good way of doing it (hence the FIXME) and it’s basically where I left off when trying to figure out all the possible code paths where we need to issue an error about a variadic friend declaration being invalid.

I’ll take another look at this once we have clarification on the cwg issue you opened earlier. Also, on that note, how would I check whether a friend declaration is trying to expand a pack that is part of the declaration itself, as opposed to some other pack?

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


More information about the cfe-commits mailing list