Title
Missing restrictions and effects for friend declarations
Status
open
Section
9.2.5 [dcl.friend]
Submitter
Tim Song

Created on 2026-05-14.00:00:00 last changed 2 weeks ago

Messages

Date: 2026-05-16.19:56:12

Possible resolution:

  1. Insert before and change in 9.2.5 [dcl.friend] paragraph 1 as follows:

    A declaration whose decl-specifier-seq contains the decl-specifier friend is a friend declaration. Such a declaration shall inhabit a class scope. It shall either be a friend-type-declaration (11.4.1 [class.mem.general]) or declare a function. [Note 1: A friend declaration can be the declaration in a template-declaration (13.1 [temp.pre], 13.7.5 [temp.friend]). —end note]

    No storage-class-specifier shall appear in the decl-specifier-seq of a friend declaration.

    The A friend specifier declaration is used to specify access to class members; see 11.8.4 [class.friend].

  2. Change in 11.8.4 [class.friend] paragraph 1 as follows:

    A friend of a class is a function or class that is given permission to name the private and protected members of the class. A class specifies its friends, if any, by way of friend declarations. A friend declaration F (9.2.5 [dcl.friend]) inhabiting the class scope of a class C specifies that C grants friendship to the class or function declared by F. Such declarations give special access rights to the friends, but they do not make the nominated friends members of the befriending class.
  3. Change in 11.8.4 [class.friend] paragraph 3 as follows:

    A friend declaration that does not declare a function shall be a friend-type-declaration. [Note 1: A friend declaration can be the declaration in a template-declaration (13.1 [temp.pre], 13.7.5 [temp.friend]). —end note]
  4. Remove 11.8.4 [class.friend] paragraph 7 as follows:

    No storage-class-specifier shall appear in the decl-specifier-seq of a friend declaration.
Date: 2026-05-14.00:00:00

(From submission #906.)

There is no rule that disallows friend declarations outside classes.

Furthermore, there is no normative text that specifies which class grants friendship. Also, there is no specification for the effects of the friend specifier on a function declaration.

History
Date User Action Args
2026-05-16 19:56:12adminsetmessages: + msg8582
2026-05-14 00:00:00admincreate