Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CWG2917 [temp.pre] Disallow multiple friend-type-specifiers if the friend-declaration is part of a template-declaration #586

Open
Sirraide opened this issue Jul 30, 2024 · 1 comment

Comments

@Sirraide
Copy link

Full name of submitter (unless configured in github; will be published with the issue): Ambrose T

Reference (section label): [temp.pre]

Issue description:

I ran into the following case while implementing variadic friends in Clang. Consider

template <typename>
friend class Foo, int;

This is obviously nonsense, but the grammar currently seems to allow it. A friend-type-declaration ([class.mem.general]) is defined as

friend-type-declaration:
  friend friend-type-specifier-list ;
friend-type-specifier-list:
  friend-type-specifier ...[opt]
  friend-type-specifier-list , friend-type-specifier ...[opt]
friend-type-specifier:
  simple-type-specifier
  elaborated-type-specifier
  typename-specifier

In p3 of that same section, we find

A member-declaration does not declare new members of the class if it is
(3.1) a friend declaration ([class.friend]), [...]
(3.3) a template-declaration whose declaration is one of the above,

which tells us that a template-declaration whose declaration is a friend-type-declaration is valid, but that doesn’t exclude the case I listed above. [temp.pre] disallows this for declarators (p5):

In a template-declaration, explicit specialization, or explicit instantiation, the init-declarator-list in the declaration shall contain at most one declarator.

But the case above, while a template-declaration, doesn’t even have declarators. It seems this case needs to be disallowed separately, but I can’t seem to find any section that would do that.

Suggested resolution:

In [temp.pre], add this to p5 (or as a separate paragraph after that; I’m not sure which would be better):

In a template-declaration whose declaration is a friend-type-declaration, the friend-type-specifier-list shall contain exactly one friend-type-specifier.

@jensmaurer
Copy link
Member

CWG2917

@jensmaurer jensmaurer changed the title [temp.pre] Disallow multiple friend-type-specifiers if the friend-declaration is part of a template-declaration CWG2917 [temp.pre] Disallow multiple friend-type-specifiers if the friend-declaration is part of a template-declaration Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants